Moya: Status code 405 returned for the first POST call of the app even when POST is an allowed method on the API.

Moya version ->10.0.1

I am made a LoginAPI class with following method implementation.

public var method: Moya.Method {
        return .post
    }

The Login Service allows only POST HTTP method. The issue is even after specifying Moya method as POST, the service response returns 405 status code in service call first time. If I retry the same call, status code 200 is returned.

Logs with 405 status code: Request: https://myURL/login Moya_Logger: [07/01/2018 21:08:54] Request Headers: [“Content-Type”: “application/json”] Moya_Logger: [07/01/2018 21:08:54] HTTP Request Method: POST Moya_Logger: [07/01/2018 21:08:54] Request Body: {“password”:”password”,”email”:”abc@del.com”} Moya_Logger: [07/01/2018 21:08:54] Response: <NSHTTPURLResponse: 0x608000038ac0> { URL: Request: https://myURL/login } { Status Code: 405, Headers { Allow = ( POST ); Date = ( “Sun, 07 Jan 2018 15:35:42 GMT” ); “Transfer-Encoding” = ( Identity ); } }

Logs with 200 Status code: Request: https://myURL/login Moya_Logger: [07/01/2018 21:12:35] Request Headers: [“Content-Type”: “application/json”] Moya_Logger: [07/01/2018 21:12:35] HTTP Request Method: POST Moya_Logger: [07/01/2018 21:12:35] Request Body: {“password”:”password”,”email”:”abc@del.com”} Moya_Logger: [07/01/2018 21:12:38] Response: <NSHTTPURLResponse: 0x60400043ab80> { URL: Request: https://myURL/login } { Status Code: 200, Headers { “Content-Type” = ( “application/json;charset=UTF-8” ); Date = ( “Sun, 07 Jan 2018 15:39:26 GMT” ); “Transfer-Encoding” = ( Identity ); } }

Points to note:

  1. This url works perfectly in Postman everytime with 200 status code with POST method.
  2. On simulator, this is the behavior first time I run the app (fresh launch of the app). On next run or on retrying , it works.
  3. Tested the api call by refactoring it to an Alamofire call, it works.

Could someone please help with what could be the possible cause for this?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 34 (17 by maintainers)

Most upvoted comments

I’ve read through the thread, but I can’t remember anything that might cause this error related with the refactoring of Task. Also the code was refactored quite a bit after me implementing the initial feature.

What I’d suggest the people seeings this issue to do:

  1. Downgrade to Moya 10.0.0 and see if the issue is there, still.
  2. Downgrade to Moya 9.0.0, possibly reverse-migrate your code if needed, then try that.

This way we can isolate the time frame the issue was introduced more exactly.

This is really strange and unfortunately all of you guys can’t share your project to help us investigate it, right?

In that case, will any of you guys (@aloco, @karbhasin, @shwetachitlangia) want to make a quick call with me and we could try debug it on the fly? Being able to reproduce it and access to the server logs would be awesome.

@shwetachitlangia Please fill in the appropriate title, help others quickly understand your problem. :]