Manos Chorianopoulos

fix refreshToken crash

...@@ -932,6 +932,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) ...@@ -932,6 +932,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
932 932
933 - (void)refreshToken:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure 933 - (void)refreshToken:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
934 { 934 {
935 + if ([_db tableExists:@"requestVariables"] == YES) {
935 FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"]; 936 FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
936 NSString *refreshToken = [NSString alloc]; 937 NSString *refreshToken = [NSString alloc];
937 while ([refreshTokenSet next]) { 938 while ([refreshTokenSet next]) {
...@@ -963,7 +964,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) ...@@ -963,7 +964,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
963 NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"]; 964 NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
964 if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) { 965 if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
965 [self refreshToken2ndTry:^(NSDictionary *response) { 966 [self refreshToken2ndTry:^(NSDictionary *response) {
966 -// [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [response objectForKey:@"access_token"], [response objectForKey:@"refresh_token"]]; 967 + // [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [response objectForKey:@"access_token"], [response objectForKey:@"refresh_token"]];
967 NSDictionary *successResponse = @{@"result": @"success", @"status":@1}; 968 NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
968 success(successResponse); 969 success(successResponse);
969 } failureBlock:^(NSError *error) { 970 } failureBlock:^(NSError *error) {
...@@ -977,6 +978,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) ...@@ -977,6 +978,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
977 NSLog(@"Error at token %@", error ); 978 NSLog(@"Error at token %@", error );
978 } 979 }
979 }]; 980 }];
981 + }
980 } 982 }
981 983
982 - (void)refreshToken2ndTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure 984 - (void)refreshToken2ndTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
......