Skip to content

Commit f27487b

Browse files
committed
chore: catch cors error by response type opaque
1 parent 182ec17 commit f27487b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

templates/web/src/client.ts.twig

+10
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,16 @@ class Client {
683683

684684
const response = await fetch(uri, options);
685685

686+
// type opaque: No-CORS, different-origin response (CORS-issue)
687+
if (response.type === 'opaque') {
688+
throw new {{spec.title | caseUcfirst}}Exception(
689+
`Invalid Origin. Register your new client (${window.location.host}) as a new Web platform on your project console dashboard`,
690+
403,
691+
"forbidden",
692+
""
693+
);
694+
}
695+
686696
const warnings = response.headers.get('x-{{ spec.title | lower }}-warning');
687697
if (warnings) {
688698
warnings.split(';').forEach((warning: string) => console.warn('Warning: ' + warning));

0 commit comments

Comments
 (0)