Search code examples
iosobjective-cnetwork-programmingafnetworkingafnetworking-3

AFNetworking - the data is loaded, but error 504 occurred


I have this code:

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

NSDictionary *parameters = @{@"client_id": some index};

[manager GET:@"some address"
  parameters:parameters
    progress:^(NSProgress * _Nonnull progress) {
        NSLog(@"In progress: %d%%", (int)([progress fractionCompleted] * 100 ));
    }
     success:^(NSURLSessionTask *task, id responseObject) {
         [self processData:[responseObject objectForKey:@"orders"]];
     }
     failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
         NSLog(@"%@", error);
     }];

It is called from viewDidLoad. Mostly it works well, but at times I get this error:

Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: gateway timed out (504)" UserInfo={NSUnderlyingError=0x7fdd40c18aa0 {Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" ...etc, nothing interesting...

However, at the console I see "In progress: 100%". In addition, in a browser I always get all the data. Hence, I propose, it is a problem of my code. How can I solve this?


Solution

  • The 504 Gateway Timeout error is an HTTP status code that means that one server did not receive a timely response from another server that it was accessing while attempting to load the web page or fill another request by the browser.

    Read more here : http://pcsupport.about.com/od/findbyerrormessage/a/504error.htm

    So nothing wrong in your code.