-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
Error message for decoding errors #208
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #208 +/- ##
==========================================
- Coverage 85.07% 85.06% -0.01%
==========================================
Files 79 79
Lines 4703 4727 +24
==========================================
+ Hits 4001 4021 +20
- Misses 702 706 +4
☔ View full report in Codecov by Sentry. |
We still support 5.6 and 5.7 so you'll need to replace the |
self.logger.debug("Decode Error: \(error)") | ||
throw HBHTTPError(.badRequest) | ||
throw HBHTTPError(.badRequest, message: error.localizedDescription) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably use "\(error)"
here. You get a much better description than you do from error.localizedDescription
usually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, in this case it makes sense. It's better to display more info.
let message = "Type mismatch for `\(path)` key, expected `\(type)` type." | ||
throw HBHTTPError(.badRequest, message: message) | ||
} | ||
catch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you catch HBHTTPError
here and then just throw it again. Otherwise if you do catch it you are throwing a HBHTTPError
that has a message that describes the HBHTTPError
you just caught. In actual fact to be correct you should catch all errors that conform to HBHTTPResponseError
catch let error as HBHTTPResponseError {
throw error
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this how you imagined? 🤔
I'd like to submit a PR for returning error messages for decoding errors.
This way users could have a better understanding about what went wrong with the input.
I also wrote some test cases to verify the changes.