javascript: fix FileUploadError stacktraces

When subclassing a JS error, most browsers include the constructor
stacktrace :/

This is an issue, because:
- The stacktrace is deeper than it should be
- The stacktrace reaches into a polyfill for which there is not source
map, which causes Sentry to infer the issue grouping from the JS file
name. And the fingerprinted name changes on each release. So for each
release, the stacktrace is different ; and Sentry can't group issues
properly.
This commit is contained in:
Pierre de La Morinerie 2020-04-22 16:21:33 +00:00
parent a583fa6391
commit 6f4075f38e

View file

@ -20,9 +20,19 @@ export const FAILURE_CONNECTIVITY = 'file-upload-failure-connectivity';
export default class FileUploadError extends Error {
constructor(message, status, code) {
super(message);
this.name = 'FileUploadError';
this.status = status;
this.code = code;
// Prevent the constructor stacktrace from being included.
// (it messes up with Sentry issues grouping)
if (Error.captureStackTrace) {
// V8-only
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = new Error().stack;
}
}
/**