From c9326697f67a54ba9b8992cbbc109ade82b697ca Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 1 Mar 2024 10:29:06 +0300 Subject: [PATCH] axios: capture more error information to sentry --- apps/web/utils/axios.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/web/utils/axios.ts b/apps/web/utils/axios.ts index 51d7272..d1678eb 100644 --- a/apps/web/utils/axios.ts +++ b/apps/web/utils/axios.ts @@ -1,7 +1,8 @@ import { HttpError } from './error'; -import { captureException } from '@sentry/nextjs'; +import { captureException, getCurrentScope } from '@sentry/nextjs'; import type { AxiosError } from 'axios'; import { isAxiosError } from 'axios'; +import { pick } from 'radash'; function getErrorMessage( error: AxiosError @@ -18,8 +19,11 @@ export async function withHandleError(fn: Promise) { return fn.catch((error_: AxiosError | Error) => { if (isAxiosError(error_)) { const message = getErrorMessage(error_); - - if (error_.response?.status && error_.response?.status >= 500) { + if (error_.config && error_.response?.status && error_.response?.status >= 500) { + const scope = getCurrentScope(); + const extras = pick(error_.config, ['url', 'data', 'params']); + scope.setExtras(extras); + scope.setTag('target_url', extras.url); error_.message += ` | ${message}`; captureException(error_);