utils/axios: capture only >500 errors
process/load-kp: remove error capture
This commit is contained in:
parent
2a8e3fb443
commit
0170d64700
@ -2,13 +2,12 @@
|
||||
import eltHelper from '../elt/lib/helper';
|
||||
import { message } from '@/Components/Common/Notification';
|
||||
import type { ProcessContext } from '@/process/types';
|
||||
import { captureException, withScope } from '@sentry/nextjs';
|
||||
import { reaction } from 'mobx';
|
||||
import { omit } from 'radash';
|
||||
|
||||
const key = 'KP_LOADING_INFO';
|
||||
|
||||
export function common({ store, trpcClient, apolloClient, user }: ProcessContext) {
|
||||
export function common({ store, trpcClient, apolloClient }: ProcessContext) {
|
||||
const { $calculation, $process, $tables } = store;
|
||||
|
||||
const { init: initElt } = eltHelper({ apolloClient, store });
|
||||
@ -86,18 +85,12 @@ export function common({ store, trpcClient, apolloClient, user }: ProcessContext
|
||||
key,
|
||||
});
|
||||
})
|
||||
.catch((error_) => {
|
||||
.catch(() => {
|
||||
message.error({
|
||||
content: `Ошибка во время загрузки КП ${quote.label}`,
|
||||
key,
|
||||
});
|
||||
$calculation.element('selectQuote').resetValue();
|
||||
|
||||
withScope((scope) => {
|
||||
scope.setExtra('quote', quote);
|
||||
scope.setExtra('user', user);
|
||||
captureException(error_);
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
$process.delete('LoadKP');
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { HttpError } from './error';
|
||||
import { captureException, withScope } from '@sentry/nextjs';
|
||||
import type { AxiosError } from 'axios';
|
||||
import { isAxiosError } from 'axios';
|
||||
@ -17,25 +18,28 @@ function getErrorMessage<T extends { error?: string; errors?: string[]; message?
|
||||
export async function withHandleError<T>(fn: Promise<T>) {
|
||||
return fn.catch((error_: AxiosError | Error) => {
|
||||
if (isAxiosError(error_)) {
|
||||
const err = pick(error_, ['code', 'message', 'status', 'cause']);
|
||||
const data = error_.config?.data;
|
||||
const params = error_.config?.params;
|
||||
|
||||
const message = getErrorMessage(error_);
|
||||
const opts = { ...err, data, message, params };
|
||||
|
||||
error_.message += ` | ${message}`;
|
||||
if (error_.response?.status && error_.response?.status >= 500) {
|
||||
const err = pick(error_, ['code', 'message', 'status', 'cause']);
|
||||
const data = error_.config?.data;
|
||||
const params = error_.config?.params;
|
||||
|
||||
withScope((scope) => {
|
||||
(Object.keys(opts) as Array<keyof typeof opts>).forEach((key) => {
|
||||
let extra = opts[key];
|
||||
if (key === 'data') extra = JSON.stringify(extra);
|
||||
scope.setExtra(key, extra);
|
||||
const opts = { ...err, data, message, params };
|
||||
|
||||
error_.message += ` | ${message}`;
|
||||
|
||||
withScope((scope) => {
|
||||
(Object.keys(opts) as Array<keyof typeof opts>).forEach((key) => {
|
||||
let extra = opts[key];
|
||||
if (key === 'data') extra = JSON.stringify(extra);
|
||||
scope.setExtra(key, extra);
|
||||
});
|
||||
captureException(error_);
|
||||
});
|
||||
captureException(error_);
|
||||
});
|
||||
}
|
||||
|
||||
throw new Error(message);
|
||||
throw new HttpError(message, error_.status || error_.response?.status);
|
||||
}
|
||||
|
||||
return null as unknown as T;
|
||||
|
||||
9
apps/web/utils/error.ts
Normal file
9
apps/web/utils/error.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export class HttpError extends Error {
|
||||
public statusCode: number;
|
||||
|
||||
constructor(message: string, statusCode = 500) {
|
||||
super(message);
|
||||
this.name = 'HttpError';
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user