Crash fix to error log instead
This commit is contained in:
parent
88a98facf5
commit
b59d755224
@ -35,10 +35,10 @@
|
||||
#pragma mark - Request Functions.
|
||||
|
||||
// Creates a request object with the given parameters.
|
||||
- (nonnull NSURLRequest *)requestWithParameters:(nonnull MVMCoreRequestParameters *)requestParameters;
|
||||
- (nullable NSURLRequest *)requestWithParameters:(nonnull MVMCoreRequestParameters *)requestParameters error:(MVMCoreErrorObject *_Nonnull *_Nonnull)error;
|
||||
|
||||
// Sends a given request to the server. When it is finished, it calls request finished, passing along the json object or nil if there is an error.
|
||||
- (nonnull NSURLSessionTask *)sendRequest:(nonnull MVMCoreRequestParameters *)requestParameters locationForError:(nonnull NSString *)locationForError requestFinished:(nullable void (^)(id _Nullable jsonObject, MVMCoreErrorObject * _Nullable error))requestFinished;
|
||||
- (nullable NSURLSessionTask *)sendRequest:(nonnull MVMCoreRequestParameters *)requestParameters locationForError:(nonnull NSString *)locationForError requestFinished:(nullable void (^)(id _Nullable jsonObject, MVMCoreErrorObject * _Nullable error))requestFinished;
|
||||
|
||||
#pragma mark - Loading Functions
|
||||
|
||||
|
||||
@ -115,7 +115,7 @@
|
||||
|
||||
#pragma mark - Request Functions.
|
||||
|
||||
- (nonnull NSURLRequest *)requestWithParameters:(nonnull MVMCoreRequestParameters *)requestParameters {
|
||||
- (nullable NSURLRequest *)requestWithParameters:(nonnull MVMCoreRequestParameters *)requestParameters error:(MVMCoreErrorObject *_Nonnull *_Nonnull)error {
|
||||
|
||||
NSURL *url = nil;
|
||||
|
||||
@ -176,9 +176,23 @@
|
||||
[parameters setObject:requestParameters.parameters forKey:@"RequestParams"];
|
||||
}
|
||||
|
||||
// Ensure the parameters are valid json.
|
||||
if (![NSJSONSerialization isValidJSONObject:parameters]) {
|
||||
if (error) {
|
||||
*error = [[MVMCoreErrorObject alloc] initWithTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeParsingJSON domain:ErrorDomainNative location:[NSString stringWithFormat:@"requestWithParameters:pageType_%@:parameters_%@",requestParameters.pageType,parameters.description]];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Logs the request parameters.
|
||||
NSError *error = nil;
|
||||
NSData *data = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted error:&error];
|
||||
NSError *jsonError = nil;
|
||||
NSData *data = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted error:&jsonError];
|
||||
if (!data) {
|
||||
if (error) {
|
||||
*error = [[MVMCoreErrorObject alloc] initWithTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] messageToLog:jsonError.localizedDescription code:jsonError.code domain:ErrorDomainSystem location:[NSString stringWithFormat:@"requestWithParameters:pageType_%@:parameters_%@",requestParameters.pageType,parameters.description]];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
MVMCoreLog(@"Request Parameters for URL %@:\n%@",[request.URL absoluteString], jsonString);
|
||||
|
||||
@ -206,9 +220,10 @@
|
||||
if (body) {
|
||||
[request setHTTPBody:body];
|
||||
} else {
|
||||
// Log the json error
|
||||
MVMCoreErrorObject *errorObject = [[MVMCoreErrorObject alloc] initWithTitle:nil message:nil code:ErrorCodeParsingJSON domain:ErrorDomainNative location:[NSString stringWithFormat:@"requestWithParameters_%@",requestParameters.pageType]];
|
||||
[MVMCoreLoggingHandler addErrorToLog:errorObject];
|
||||
if (error) {
|
||||
*error = [[MVMCoreErrorObject alloc] initWithTitle:nil message:nil code:ErrorCodeParsingJSON domain:ErrorDomainNative location:[NSString stringWithFormat:@"requestWithParameters_%@",requestParameters.pageType]];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
return request;
|
||||
@ -280,7 +295,7 @@
|
||||
return body;
|
||||
}
|
||||
|
||||
- (nonnull NSURLSessionTask *)sendRequest:(nonnull MVMCoreRequestParameters *)requestParameters locationForError:(nonnull NSString *)locationForError requestFinished:(nullable void (^)(id _Nullable jsonObject, MVMCoreErrorObject *_Nullable error))requestFinished {
|
||||
- (nullable NSURLSessionTask *)sendRequest:(nonnull MVMCoreRequestParameters *)requestParameters locationForError:(nonnull NSString *)locationForError requestFinished:(nullable void (^)(id _Nullable jsonObject, MVMCoreErrorObject *_Nullable error))requestFinished {
|
||||
|
||||
#if ENABLE_HARD_CODED_RESPONSE
|
||||
NSDictionary *response = [[MFHardCodedServerResponse sharedInstance] getHardCodedResponseForRequest:requestParameters];
|
||||
@ -291,9 +306,16 @@
|
||||
return nil;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
MVMCoreErrorObject *error = nil;
|
||||
NSTimeInterval startTime = [NSDate timeIntervalSinceReferenceDate];
|
||||
NSURLRequest *request = [self requestWithParameters:requestParameters];
|
||||
NSURLRequest *request = [self requestWithParameters:requestParameters error:&error];
|
||||
if (!request) {
|
||||
if (requestFinished) {
|
||||
requestFinished(nil,error);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
NSURLSession *session = [MVMCoreSessionObject sharedGlobal].session;
|
||||
|
||||
if ([[MFFreebeeHandler sharedHandler] isFreeBeeEnabled]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user