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) isnil
. 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
- Modifies mapJSON to take optional failsOnEmptyData parameter (#568) [Enhancement (bug? fix)] Modified function `Response.mapJSON` to take an optional parameter `failsOnEmptyData:` to give users contr... — committed to Moya/Moya by spxrogers 8 years ago
- Modifies mapJSON to take optional failsOnEmptyData parameter (#568) [Enhancement (bug? fix)] Modified function `Response.mapJSON` to take an optional parameter `failsOnEmptyData:` to give users contr... — committed to Moya/Moya by spxrogers 8 years ago
So it looks like a PR to fix this issue would modify the
mapJSON
function.We would need to add a new parameter like
failsOnEmptyResponse: Bool = true
. If itโsfalse
anddata == nil
, we need to return some other value. An emptyNSArray
orNSDictionary
might work, or maybeNSNull()
. Not sure, open for discussion.Oh, and we should test it, too ๐