Skip to content

Commit

Permalink
Fix throw of non success error codes (#151)
Browse files Browse the repository at this point in the history
* Fix throw of non success error codes

* Another case
  • Loading branch information
mxsc authored Nov 28, 2024
1 parent 17eeeac commit 6021d6f
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ case \(statusCode.rawValue):
} else {
return """
case \(statusCode.rawValue):
let result: \(responseType.modelNamed)
do {
let result = try decoder.decode(\(responseType.modelNamed).self, from: data)
\(failed ? "throw" : "return") \(resultType("result", resultIsEnum))
result = try decoder.decode(\(responseType.modelNamed).self, from: data)
} catch let error {
interceptor?.networkFailedToParseObject(
urlRequest: request,
Expand All @@ -80,6 +80,7 @@ case \(statusCode.rawValue):
)
throw \(errorType).requestFailed(error: error)
}
\(failed ? "throw" : "return") \(resultType("result", resultIsEnum))
"""
}
case .void(let statusCode, let resultIsEnum):
Expand Down Expand Up @@ -177,12 +178,13 @@ case \(statusCode.rawValue):
case .array(let statusCode, let resultIsEnum, let innerType):
return """
case \(statusCode.rawValue):
let result: [\(innerType)]
do {
let result = try decoder.decode([\(innerType)].self, from: data)
\(failed ? "throw" : "return") \(resultType("result", resultIsEnum))
result = try decoder.decode([\(innerType)].self, from: data)
} catch let error {
throw \(errorType).requestFailed(error: error))
}
\(failed ? "throw" : "return") \(resultType("result", resultIsEnum))
"""
case .enumeration(let statusCode, let resultIsEnum, let responseType):
// This is necessary as iOS 12 doesnt support JSON fragments in JSONDecoder,
Expand Down

0 comments on commit 6021d6f

Please sign in to comment.