(errorhandling) ignore loading errors for ad and gtm scripts

most of the time these are CORS errors which need separate investigation
but as these errors are quite common, they keep coming in sentry
This commit is contained in:
Valentyne Stigloher 2024-03-10 17:44:08 +01:00
parent f990ebf1fd
commit 14ee946971
3 changed files with 25 additions and 3 deletions

View File

@ -40,6 +40,7 @@ import dark from '../plugins/dark.ts';
import sorter from 'avris-sorter';
import { sleep } from '../src/helpers.ts';
import md5 from 'js-md5';
import { LoadScriptError } from '../src/errors.ts';
import type { default as dialogueBox, DialogueMessage } from '../components/DialogueBox.vue';
import type { Color } from '../src/bootstrap.ts';
@ -217,14 +218,28 @@ export default dark.extend({
return;
}
await this.$loadScript('publift', 'https://cdn.fuseplatform.net/publift/tags/2/3329/fuse.js');
try {
await this.$loadScript('publift', 'https://cdn.fuseplatform.net/publift/tags/2/3329/fuse.js');
} catch (error) {
if (error instanceof LoadScriptError) {
return;
}
throw error;
}
},
async loadGTM(): Promise<void> {
if (!this.adsEnabled) {
return;
}
await this.$loadScript('gtm', 'https://www.googletagmanager.com/gtag/js?id=G-TDJEP12Q3M');
try {
await this.$loadScript('gtm', 'https://www.googletagmanager.com/gtag/js?id=G-TDJEP12Q3M');
} catch (error) {
if (error instanceof LoadScriptError) {
return;
}
throw error;
}
window.dataLayer = window.dataLayer || [];
function gtag(..._args: unknown[]): void {

View File

@ -11,6 +11,7 @@ import type { RootState } from '../store/index.ts';
import translations from '../data/translations.suml';
import baseTranslations from '../locale/_base/translations.suml';
import { LoadScriptError } from '../src/errors.ts';
declare global {
interface Window {
@ -96,7 +97,7 @@ export default ({ app, store }: { app: Vue, store: Store<RootState> }): void =>
script.crossOrigin = 'true';
script.addEventListener('load', () => resolve());
script.addEventListener('error', (event) => {
reject(new Error(`failed to load ${name} (${src}): ${typeof event === 'string' ? event : event.type}`));
reject(new LoadScriptError(name, src, typeof event === 'string' ? event : event.type));
});
document.body.appendChild(script);
});

6
src/errors.ts Normal file
View File

@ -0,0 +1,6 @@
export class LoadScriptError extends Error {
constructor(scriptName: string, src: string, type: string) {
super(`failed to load ${scriptName} (${src}): ${type}`);
this.name = this.constructor.name;
}
}