From f27487b1598a561762a0755eeeac4dec46dcf6d6 Mon Sep 17 00:00:00 2001 From: ChiragAgg5k Date: Wed, 16 Apr 2025 16:47:52 +0530 Subject: [PATCH] chore: catch cors error by response type opaque --- templates/web/src/client.ts.twig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/templates/web/src/client.ts.twig b/templates/web/src/client.ts.twig index e5c0beb14..7a5be73e1 100644 --- a/templates/web/src/client.ts.twig +++ b/templates/web/src/client.ts.twig @@ -683,6 +683,16 @@ class Client { const response = await fetch(uri, options); + // type opaque: No-CORS, different-origin response (CORS-issue) + if (response.type === 'opaque') { + throw new {{spec.title | caseUcfirst}}Exception( + `Invalid Origin. Register your new client (${window.location.host}) as a new Web platform on your project console dashboard`, + 403, + "forbidden", + "" + ); + } + const warnings = response.headers.get('x-{{ spec.title | lower }}-warning'); if (warnings) { warnings.split(';').forEach((warning: string) => console.warn('Warning: ' + warning));