-
Notifications
You must be signed in to change notification settings - Fork 17
Description
The + (NSError *)authenticationErrorForResponse:(NSDictionary *)response in BaasBox.m
crashes.
Reason (original code below):
-
(NSError *)authenticationErrorForResponse:(NSDictionary *)response {
if (response == nil) {
NSDictionary *errorDetail = @{NSLocalizedDescriptionKey:@"Server returned an empty response.",
@"BaasBox API Version": @[response[@"API_version"]],
// ---> KV coding an dictionary cannot save a nil reference and response and so the requested object is nil !!!@"iOS SDK Version" : VERSION}; return [NSError errorWithDomain:[BaasBox errorDomain] code:-22222 userInfo:errorDetail];}
NSDictionary *errorDetail = @{NSLocalizedDescriptionKey:response[@"message"],
@"BaasBox_API_version": @[response[@"API_version"]],
@"iOS SDK Version" : VERSION};
NSError *error = [NSError errorWithDomain:[BaasBox errorDomain]
code:-22222
userInfo:errorDetail];
return error;
}
Consider the following fix, wich will in addition make the code more compact and readable:
-
(NSError *)authenticationErrorForResponse:(NSDictionary *)response
{
NSString *message = response[@"message"] ? response[@"message"] : @"Server returned an empty response.";
NSString *apiVersion = response[@"API_version"] ? response[@"API_version"] : @"unknown";NSDictionary *errorDetail = @{NSLocalizedDescriptionKey:message,
@"BaasBox API Version": apiVersion,
@"iOS SDK Version" : VERSION};NSError *error = [NSError errorWithDomain:[BaasBox errorDomain]
code:-22222
userInfo:errorDetail];
return error;
}