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
axios capture response message #4377
Comments
We pass in the You can also override the
|
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
@AbhiPrasad it would be helpful if your docs had a more thorough description of handling this as axios is a very commonly used library. |
did this the trick for me. |
My solution, based on @Freundschaft's code: import { AxiosError, isAxiosError } from "axios";
Sentry.init({
//...
beforeSend: handleSentryBeforeSend
});
function handleSentryBeforeSend(event: Event, hint: EventHint) {
addAxiosContextRecursive(event, hint?.originalException);
}
function addAxiosContextRecursive(event: Event, error: unknown) {
if (isAxiosError(error)) {
addAxiosContext(event, error);
} else if (error instanceof Error && error.cause) {
addAxiosContextRecursive(event, error.cause);
}
}
function addAxiosContext(event: Event, error: AxiosError) {
if (error.response) {
const contexts = { ...event.contexts };
contexts.Axios = { Response: error.response };
event.contexts = contexts;
}
} This works in TypeScript and it also handles recursive errors (i.e. when |
hi,
in case of axios if you do request and axios returns 400, the error logged by Sentry contains minimum amount of data which in most cases is not useful. It just says "request failed with response 400", but there is actually no response data why it failed.
What is the preferred way/place to make Sentry capture more information in case of
AxiosError
?this is what I came up with currently:
that seems to be alright, although not sure if it is the correct way. Maybe a way to modify ExtraErrorData and pass some kind of extra function that allows me to check if error is AxiosError and then provide the fields I am interested in?
Or is using context more appropriate?
The text was updated successfully, but these errors were encountered: