-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: Wrap AxiosErrors in custom error object #151
Conversation
This is a really good idea - we should absolutely be giving consuming libraries everything they need to interface with the errors we throw here. Should definitely be very careful to make sure we don't lose any info contained in the errors along the way, but I don't really see a downside to doing this |
My understanding is that by creating the new error type and setting the error thrown by axios as cause we preserve all of the stack trace context. We can also still access the axios error fields in the event there is a piece of information we don't have available on the top level of the new error. |
…/hubspot-local-dev-lib into jy/POC-Wrap-Axios-Errors
…jy/POC-Wrap-Axios-Errors
…jy/POC-Wrap-Axios-Errors
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.
Besides the one tiny nit, this all looks great to me. Particularly like how you made the request fields top level in HubSpot errors. Chef's kiss👩🍳 💋
export function getAxiosErrorWithContext( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
error: AxiosError<any>, | ||
export function getHubSpotHttpErrorWithContext( |
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.
Just recording here that this will be a major version bump since it's a breaking change (totally fine, just wanted to add a comment for posterity)
Description and Context
I think our http functions could be considered a leaky abstraction because we are directly exposing
AxiosErrors
which requires the projects depending on these functions to writeaxios
specific logic in their code base, such as checkinge.response && e.response.status
in catch blocks. What I am proposing is that we globally wrap allAxiosErrors
in our own customError
to keep the implementation details limited to this repository.This would mean that error checking could be simplified from something like:
So the resulting code is completely unaware that
axios
is being used under the hood.Who to Notify
@brandenrodgers @camden11 @kemmerle