From 4dfc2354a96b0da9035cad2ebb5f1ccfd6abb9d3 Mon Sep 17 00:00:00 2001 From: Nick Satterly Date: Sun, 13 Dec 2020 00:18:01 +0100 Subject: [PATCH] fix: add helpful error message if susupected CORS issue --- src/services/api/interceptors.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/services/api/interceptors.ts b/src/services/api/interceptors.ts index b92c0612..2047c676 100644 --- a/src/services/api/interceptors.ts +++ b/src/services/api/interceptors.ts @@ -1,5 +1,6 @@ import { store } from '@/main' import { v4 as uuidv4 } from 'uuid' +import axios from 'axios' export function makeInterceptors(router) { return { @@ -11,6 +12,18 @@ export function makeInterceptors(router) { // response handlers interceptErrors(error) { + if (!error.response && !axios.isCancel(error)) { + alert( + 'ERROR: A network error occurred. This could be a CORS issue or a ' + + 'dropped internet connection.\n\n' + + 'Check the browser javascript console and if the HTTP request has ' + + 'been blocked by CORS then ensure that the "X-Request-ID" ' + + 'header is in the "CORS_ALLOW_HEADERS" list in the Alerta API ' + + 'configuration, or upgrade the Alerta API server to version 8.3.0 or ' + + 'later.' + ) + } + if (error.response) { store.dispatch('notifications/error', error.response.data) }