From 10f6378cf0cef7b7efb28806be9ad5689e4620f9 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 11 May 2022 12:32:22 +0200 Subject: [PATCH] fix(upload): silence common client errors in sentry --- .../controllers/autosave_controller.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/javascript/controllers/autosave_controller.ts b/app/javascript/controllers/autosave_controller.ts index 824f354d5..547321fca 100644 --- a/app/javascript/controllers/autosave_controller.ts +++ b/app/javascript/controllers/autosave_controller.ts @@ -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.