Moya: Moya says that response is nil after coming back to the app from lock screen

Hi,

Here is the case:

  • return to the app from the lock screen;
  • nearly immediately (1-2 seconds) send the HTTP request via moya;

Actual Result:

  • moya returns error Moya.Error.Underlying and says that the response (NSHTTPURLResponse) is nil. NSError contains - error NSError? domain: "NSURLErrorDomain" - code: 18446744073709550611 0x000000012c5d9700

Note: The code where this debug info caught: File: Moya.swift Func: internal func convertResponseToResult(response: NSHTTPURLResponse?, data: NSData?, error: NSError?) -> Result<Moya.Response, Moya.Error>

It could be steadily reproduced only within 1-2 seconds after returning to the application from the lock screen.

Please help.

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Comments: 23 (12 by maintainers)

Commits related to this issue

Most upvoted comments

So it looks like a PR to fix this issue would modify the mapJSON function.

func mapJSON() throws -> AnyObject {
    do {
        return try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)
    } catch {
        throw Error.Underlying(error as NSError)
    }
}

We would need to add a new parameter like failsOnEmptyResponse: Bool = true. If itโ€™s false and data == nil, we need to return some other value. An empty NSArray or NSDictionary might work, or maybe NSNull(). Not sure, open for discussion.

Oh, and we should test it, too ๐Ÿ˜‰