Skip to content

Commit

Permalink
Merge pull request #297 from EnMarche/fix/sentry-back-error-logging
Browse files Browse the repository at this point in the history
ETQDev, je ne vois pas les erreurs lors des call au back catchés dans Sentry
  • Loading branch information
BastienTeissier authored Apr 13, 2021
2 parents 1a47666 + df19890 commit 170e8c6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 1 addition & 7 deletions src/redux/useTypedAsyncFn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useAsyncFn } from 'react-use';
import * as Sentry from '@sentry/browser';

/**
* A wrapper around useAsyncFn until its arguments can be properly typed
Expand All @@ -12,11 +11,6 @@ import * as Sentry from '@sentry/browser';

export function useTypedAsyncFn<T>(callback: (input: T) => Promise<any>, deps: any[]) {
return useAsyncFn(async (...args: T[]) => {
try {
return await callback(args[0]);
} catch (err) {
Sentry.captureException(err);
throw err;
}
return await callback(args[0]);
}, deps);
}
10 changes: 8 additions & 2 deletions src/services/HandleErrorService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import debounce from 'lodash/debounce';
import * as Sentry from '@sentry/browser';
import { store } from 'redux/store';
import { updateSnackbar } from 'redux/Snackbar';
import { Severity } from 'redux/Snackbar/types';
import debounce from 'lodash/debounce';

export type APIErrorsType = Response | Error;
type DefaultHandlerType = (error?: APIErrorsType) => string | null;
Expand All @@ -28,7 +29,11 @@ export default class HandleErrorService {
return defaultMessage;
}
const errorMessage = defaultHandler(error);
return errorMessage !== null ? errorMessage : defaultMessage;
if (errorMessage !== null) {
return errorMessage;
}
Sentry.captureException(error);
return defaultMessage;
}

static getErrorMessage(error?: APIErrorsType, defaultHandler?: DefaultHandlerType) {
Expand All @@ -41,6 +46,7 @@ export default class HandleErrorService {
} else if (error instanceof Response && HandleErrorService.isNoBackConnectionError(error)) {
return ERROR_MESSAGES.unableToJoinServer;
} else if (error instanceof Response && error.status >= 500) {
Sentry.captureException(error);
return ERROR_MESSAGES.error500;
}

Expand Down

0 comments on commit 170e8c6

Please sign in to comment.