Merge pull request #5051 from betagouv/report-filereader-errors-to-sentry
javascript: report upload FileReader errors to Sentry
This commit is contained in:
commit
76ce622ebf
1 changed files with 32 additions and 0 deletions
|
@ -1,7 +1,13 @@
|
|||
import Rails from '@rails/ujs';
|
||||
import AutoUploadController from './auto-upload-controller.js';
|
||||
import { fire } from '@utils';
|
||||
import { FAILURE_CONNECTIVITY } from '../../shared/activestorage/file-upload-error';
|
||||
|
||||
//
|
||||
// DEBUG
|
||||
//
|
||||
const originalImpl = FileReader.prototype.addEventListener;
|
||||
|
||||
// Manage multiple concurrent uploads.
|
||||
//
|
||||
// When the first upload starts, all the form "Submit" buttons are disabled.
|
||||
|
@ -36,6 +42,25 @@ export default class AutoUploadsControllers {
|
|||
.querySelectorAll('button[type=submit]')
|
||||
.forEach(submitButton => Rails.disableElement(submitButton));
|
||||
}
|
||||
|
||||
//
|
||||
// DEBUG: hook into FileReader onload event
|
||||
//
|
||||
if (FileReader.prototype.addEventListener === originalImpl) {
|
||||
FileReader.prototype.addEventListener = function() {
|
||||
// When DirectUploads attempts to add an event listener for "error",
|
||||
// also insert a custom event listener of our that will report errors to Sentry.
|
||||
if (arguments[0] == 'error') {
|
||||
let handler = event => {
|
||||
let message = `FileReader ${event.target.error.name}: ${event.target.error.message}`;
|
||||
fire(document, 'sentry:capture-exception', new Error(message));
|
||||
};
|
||||
originalImpl.apply(this, ['error', handler]);
|
||||
}
|
||||
// Add the originally requested event listener
|
||||
return originalImpl.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
_decrementInFlightUploads(form) {
|
||||
|
@ -48,5 +73,12 @@ export default class AutoUploadsControllers {
|
|||
.querySelectorAll('button[type=submit]')
|
||||
.forEach(submitButton => Rails.enableElement(submitButton));
|
||||
}
|
||||
|
||||
//
|
||||
// DEBUG: remove the FileReader hook we set before.
|
||||
//
|
||||
if (this.inFlightUploadsCount == 0) {
|
||||
FileReader.prototype.addEventListener = originalImpl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue