-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
How to handle 422 json error response? #69
Comments
You can throw a custom error by implementing It might be worth also expanding |
Thanks @kean, client(_:validateResponse:data:task:) is useful for the scenario of logging all error messages, bug reporting, etc. I think you're on to something by expanding |
It is also designed for providing a way to generate custom errors instead of |
I'm prototyping an improved version of async API for Get 3.0 to address Xcode 14.3 warnings. I think it'll work nicely for decoding custom errors. let dataTask = await client.dataTask(with: Request<User>(path: "/user"))
if #available(iOS 15, *) {
for await progress in dataTask.progress.values {
print(progress)
}
}
do {
let response = try await dataTask.response.value
} catch {
let data = try await dataTask.data
// Parse error
} It could probably be improved further. Currently, if the server responds with 422, the entire let response = await dataTask.response
do {
let value = try await response.value // Decodes the value
} catch {
// Catch all errors here
if let data = response.data {
// You change to parses data
}
} |
Our api server gives a 422 response when validating request params:
However,
Get
only supplies the error code:Response status code was unacceptable: 422
viaAPIError
How can we hook into the actual error response for logging and (sometimes) showing to the user?
The text was updated successfully, but these errors were encountered: