Merge pull request #7292 from tchak/fix-mute-errors-in-sentry

fix(upload): silence common client errors in sentry
This commit is contained in:
Paul Chavard 2022-05-11 13:50:10 +02:00 committed by GitHub
commit 79d5946ab6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,11 @@ import { z } from 'zod';
import { ApplicationController } from './application_controller';
import { AutoUpload } from '../shared/activestorage/auto-upload';
import {
FileUploadError,
FAILURE_CLIENT,
ERROR_CODE_READ
} from '../shared/activestorage/file-upload-error';
const Gon = z.object({ autosave: z.object({ debounce_delay: z.number() }) });
@ -95,7 +100,19 @@ export class AutosaveController extends ApplicationController {
private enqueueAutouploadRequest(target: HTMLInputElement, file: File) {
const autoupload = new AutoUpload(target, file);
autoupload.start();
try {
autoupload.start();
} catch (e) {
const error = e as FileUploadError;
// Report unexpected client errors to Sentry.
// (But ignore usual client errors, or errors we can monitor better on the server side.)
if (
error.failureReason == FAILURE_CLIENT &&
error.code != ERROR_CODE_READ
) {
throw error;
}
}
}
// Add a new autosave request to the queue.