Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix throw of non success error codes #151

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading