is there an easy way to get the http status code in the failure block from AFHTTPClient?

前端 未结 6 1754
猫巷女王i
猫巷女王i 2020-12-13 01:05

I see that there is a list of accepted http status codes that I can modify, but I think it would be cleaner if I can get the http status code in the failure block ..

6条回答
  •  误落风尘
    2020-12-13 01:52

    NSInteger operationStatusCode = [operation.error code];

    NSInteger httpStatusCode = operation.response.statusCode;

    If the requests were cancelled/unreachable/timeout, httpStatusCode will be always 0.

    Alternatively you can identify the issue by understanding the operationStatusCode. It is a NSError Object.

    • If it cannot reach/timeout/no network to process request, the operationStatusCode will be -1009.
    • If you cancel the operations queue the operationStatusCode will be -999.

    You can check all other NSError codes and their descriptions in Apple's documentation

提交回复
热议问题