fix(upload): silence common client errors in sentry

This commit is contained in:
Paul Chavard 2022-05-11 12:32:22 +02:00
parent 30f3130e87
commit 10f6378cf0

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);
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.