-
Notifications
You must be signed in to change notification settings - Fork 29
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
Custom error is returned from custom validator and/or decode() function #34
Comments
May you post the structure of |
it's very simple struct:
|
Okay I've fixed the dispatch of custom errors. Moreover I decided to dispatch original response of the request and attach additional error information based upon the library activity (max attempts, validation errors etc.). |
it works when I use let response = try await request.fetch()
// now, response.error?.error is MyError but when I use let myModel = try await request.fetch(MyModel.self) the error isn't thrown if the body can be encoded. I would have expected that somehow I get to the error then as well, but there's no way as let response = try await request.fetch()
// check if response.error?.error is set, if not:
let myModel = try response.decode(MyModel.self) |
You are absolutely right, the fetch error should be passed outside the do {
_ = try await req.fetch(client: newClient, DummyDecodeStruct.self)
} catch {
let customUnderlyingError = (error as? HTTPError)?.error as? MyError
print(customUnderlyingError)
} |
…dispatch received error from network outside
ok I've fixed the code and added the necessary unit test |
#34 Fix for custom error dispatch for decode() and throws
I have a custom validator like this:
And I get to the last line as expected, so a
MyError
is returned, wrapped into thefailChain
.But in my calling code:
an error is thrown (expected) but it is an
HTTPError
with an emptyerror
property, so myMyError
isn't available hereThe text was updated successfully, but these errors were encountered: