From 558e3c7499f917a94ad58e86a123857289b31ec1 Mon Sep 17 00:00:00 2001 From: Chad Burggraf Date: Mon, 18 Jul 2022 20:29:50 -0700 Subject: [PATCH] fix: Catch audio context errors (#5051) Prevent errors in decoding and playing sounds from propagating by catching them in the promise chain. Fixes #4281. --- .../shared/helpers/AudioNotificationHelper.js | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/app/javascript/shared/helpers/AudioNotificationHelper.js b/app/javascript/shared/helpers/AudioNotificationHelper.js index c3108f174..7db280fa2 100644 --- a/app/javascript/shared/helpers/AudioNotificationHelper.js +++ b/app/javascript/shared/helpers/AudioNotificationHelper.js @@ -16,19 +16,18 @@ export const getAlertAudio = async (baseUrl = '', type = 'dashboard') => { }; }; - try { - const resourceUrl = `${baseUrl}/audio/${type}/ding.mp3`; - const audioRequest = new Request(resourceUrl); + const resourceUrl = `${baseUrl}/audio/${type}/ding.mp3`; + const audioRequest = new Request(resourceUrl); - fetch(audioRequest) - .then(response => response.arrayBuffer()) - .then(buffer => { - audioCtx.decodeAudioData(buffer).then(playsound); - return new Promise(res => res()); - }); - } catch (error) { - // error - } + fetch(audioRequest) + .then(response => response.arrayBuffer()) + .then(buffer => { + audioCtx.decodeAudioData(buffer).then(playsound); + return new Promise(res => res()); + }) + .catch(() => { + // error + }); }; export const notificationEnabled = (enableAudioAlerts, id, userId) => {