Search code examples
iosswiftalamofire

Validate Alamofire Response for both HTTP 200 and 500 status codes


I want to use Alamofire.request.validate() to validate http status code and return error If It doesn't pass the rule. As you know, It default check if It is 2xx. However, I want to add also HTTP 500. I tried to do Alamofire.request.validate().validate(500) but It doesn't work. In addition, because It accept sequence only, I can't use || operator. How can I achieve this? Thank you.

I got help from below post but can't find anything about my problem.

What is the use of the validate() method in Alamofire.request?


Solution

  • I can make Alamofire validate only HTTP 200 and HTTP 500 status codes by putting status codes inside an array and give as an input. Hope It helps:

    Alamofire.request(route).validate(statusCode: [200,500]).responseJSON