Log upload errors into Sentry (#4444)

Les erreurs d'envoi de pièces jointes sont signalées à Sentry
This commit is contained in:
Pierre de La Morinerie 2019-10-24 16:24:17 +02:00 committed by GitHub
commit 669773fa47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -1,4 +1,5 @@
import ProgressBar from './progress-bar'; import ProgressBar from './progress-bar';
import { fire } from '@utils';
const INITIALIZE_EVENT = 'direct-upload:initialize'; const INITIALIZE_EVENT = 'direct-upload:initialize';
const START_EVENT = 'direct-upload:start'; const START_EVENT = 'direct-upload:start';
@ -36,8 +37,18 @@ addUploadEventListener(PROGRESS_EVENT, ({ detail: { id, progress } }) => {
ProgressBar.progress(id, progress); ProgressBar.progress(id, progress);
}); });
addUploadEventListener(ERROR_EVENT, ({ detail: { id, error } }) => { addUploadEventListener(ERROR_EVENT, event => {
ProgressBar.error(id, error); // Display an error message
alert(
`Nous sommes désolés, une erreur sest produite lors de lenvoi du fichier.
(${event.detail.error})`
);
// Prevent ActiveStorage from displaying its own error message
event.preventDefault();
ProgressBar.error(event.detail.id, event.detail.error);
fire(document, 'sentry:capture-exception', new Error(event.detail.error));
}); });
addUploadEventListener(END_EVENT, ({ detail: { id } }) => { addUploadEventListener(END_EVENT, ({ detail: { id } }) => {

View file

@ -10,4 +10,10 @@ if (enabled && key) {
scope.setUser(user); scope.setUser(user);
scope.setExtra('browser', browser.modern ? 'modern' : 'legacy'); scope.setExtra('browser', browser.modern ? 'modern' : 'legacy');
}); });
// Register a way to explicitely capture messages from a different bundle.
addEventListener('sentry:capture-exception', event => {
const error = event.detail;
Sentry.captureException(error);
});
} }