You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 !!!
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 !!!
}
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;
}
The text was updated successfully, but these errors were encountered: