-
Notifications
You must be signed in to change notification settings - Fork 213
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
(chore) Add FetchError interface for more granular error typing #1230
Conversation
This PR adds a `FetchError` interface to the framework that can be used to annotate errors that occur during fetch requests. It also amends the `OpenmrsFetchError` class to implement the `FetchError` interface. Presently, the openmrsFetch hook throws a custom `OpenmrsFetchError` class that includes the response status code and status text if a request fails. This is not always the most helpful message, and it's not always clear what the underlying error was. The REST API returns a more useful message in the responseBody, and it would be preferable to show this message instead of the status code and status text. With this change, we can then use the FetchError interface further down the line in SWR hooks to annotate errors.
Size Change: -87.4 kB (-1.4%) Total Size: 6.15 MB
ℹ️ View Unchanged
|
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.
I'm fine with this, but is there any superiority to using FetchError
rather than OpenmrsFetchError
in the SWR typings?
Not at all. Is |
Well, the class itself is exported, so the types should be there by default. |
For anyone wondering what the resolution here was - |
Requirements
feat
,fix
, orchore
, among others). See existing PR titles for inspiration.For changes to apps
If applicable
Summary
This PR adds a
FetchError
interface to the framework that can be used to annotate errors that occur during fetch requests. It also amends theOpenmrsFetchError
class to implement theFetchError
interface. Presently, theopenmrsFetch
hook throws a custom error that includes the response status code and status text if a request fails. This is not always the most helpful message, and it's not always clear what the underlying error was.The REST API returns a more useful message in the responseBody, and it would be preferable to show this message instead of the status code and status text. With this change, we can then use the FetchError interface further down the line in SWR hooks to annotate errors.
Screenshots
Related Issue
Other