Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as Sentry from '@sentry/browser'
import { SENTRY_CONFIG } from '../config/config'
export const log = {
message: Sentry.captureMessage,
event: Sentry.captureEvent,
exception: Sentry.captureException,
}
export const Level = Sentry.Severity
export const initErrorHandler = () => {
if (
location.search.indexOf('noSentry=true') !== -1 ||
location.hostname === 'localhost'
) {
return
}
// please check https://docs.sentry.io/error-reporting/configuration/?platform=javascript for options
Sentry.init({
dsn: SENTRY_CONFIG.dsn,
})
}
Sentry.withScope(scope => {
// `requestPromise` can pass its error object
const preservedError = options.preservedError || errorObject;
const errorObjectToUse = createRequestError(
resp,
preservedError.stack,
method,
path
);
errorObjectToUse.removeFrames(2);
// Setting this to warning because we are going to capture all failed requests
scope.setLevel(Sentry.Severity.Warning);
scope.setTag('http.statusCode', String(resp.status));
Sentry.captureException(errorObjectToUse);
});
}
handleError(error, args) {
const [stateKey] = args;
if (error && error.responseText) {
Sentry.addBreadcrumb({
message: error.responseText,
category: 'xhr',
level: Sentry.Severity.Error,
});
}
this.setState(prevState => {
const loading = prevState.remainingRequests! > 1;
const state: AsyncComponentState = {
[stateKey]: null,
errors: {
...prevState.errors,
[stateKey]: error,
},
error: prevState.error || !!error,
remainingRequests: prevState.remainingRequests! - 1,
loading,
reloading: prevState.reloading && loading,
};
this.markShouldMeasure({remainingRequests: state.remainingRequests, error: true});
Sentry.withScope(scope => {
scope.setLevel(Sentry.Severity.Warning);
scope.setFingerprint(['sentry-locale-not-found']);
scope.setExtra('locale', language);
Sentry.captureException(e);
});
useLayoutEffect(() => {
if (!isEnabled) { return }
const wasUndo = pointer < lastPointerRef.current
lastPointerRef.current = pointer
const { type } = action
Sentry.addBreadcrumb({
category: 'action',
message: `${type}${wasUndo ? ' (Undo)' : ''}`,
data: action,
level: Sentry.Severity.Info,
})
}, [action, pointer, isEnabled])
}
Sentry.withScope(scope => {
if (params[0] instanceof Error) {
scope.setExtra('exception', params[0].stack);
}
scope.setExtra('console-args', JSON.stringify(params, null, 2));
Sentry.captureMessage(msg, Sentry.Severity.Error);
});
};