1

i am using AFNetworking framework in the my project & accessing webservice via AFHTTPSessionManager class like following way,

AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager.requestSerializer setTimeoutInterval:30];

NSDictionary *parametersDictionary = @{
                             @"users_id":userIDStr,
                             @"name" :@""

                             };
[manager POST:@"api/call_XAPI?"
                                      parameters:parametersDictionary
                                        progress:^(NSProgress * _Nonnull uploadProgress) {

                                        }
                                         success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {                                                 
                                                                         NSLog(@"Success");                       

                                         } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                                                                                                     NSLog(@"%@", error);                
                                         }];

This is working properly on success but when if any error occurs in server then error response not getting in proper format on the console

Printing description of error:
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x608000435940> { URL: http://www.example.com/api/call_XYZAPI? } { status code: 500, headers {
"Cache-Control" = "no-cache";
Connection = "keep-alive";
"Content-Type" = "application/json";
Date = "Mon, 30 Jan 2017 13:12:59 GMT";
Server = "nginx/1.10.2";
"Set-Cookie" = "laravel_session=ca9b0725b981267be1f095bb6ae14a1d5ae2825f; expires=Mon, 30-Jan-2017 15:12:59 GMT; Max-Age=7200; path=/; httponly";
"Transfer-Encoding" = Identity;
} }, NSErrorFailingURLKey=http://www.example.com/api/call_XYZAPI?, com.alamofire.serialization.response.error.data = 12112,23131,31231331,312231 ..... 

Can anyone tell me what i am doing wrong & how to resolve this issue?

Mukesh Lokare
  • 2,159
  • 26
  • 38

1 Answers1

0

According to this article, the error 500 has nothing to do with the client and should be handled on web service server.

Contact your backend developer and ask him to fix it.

Yogi
  • 3,578
  • 3
  • 35
  • 56
  • Yes @Yogi you are correct,we already resolved this issue, But my question is error response is not in proper format. –  Jan 31 '17 at 05:29
  • I think you should have a look at contents of `NSHTTPURLResponse` object. Mostly it has the response from server in better format. I assume that you require it to let the user know about the error by presenting an error alert or so. – Yogi Jan 31 '17 at 05:32
  • When you got a `internal server error (500) `, the terminal log as you printed is ok, do not worry about it. – nynohu Jan 31 '17 at 05:32
  • Yeah @nynohu sir i have handled all status code too but i am just curious about error format. –  Jan 31 '17 at 05:39
  • You can `try NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; int statuscode = response.statusCode;` for get error code – nynohu Jan 31 '17 at 05:46
  • Yes @nynohu i already did it. But my question is this error format is correct when any error occurs from backend. –  Jan 31 '17 at 05:51