From 41c3b99fbe0efe767a8626a19d3df460b54d4db2 Mon Sep 17 00:00:00 2001 From: Gareth Redfern Date: Mon, 11 Jan 2021 16:29:05 +0000 Subject: [PATCH] check for error.response in axios interceptors --- src/services/API.js | 5 ++++- src/services/AuthService.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/services/API.js b/src/services/API.js index a82eade..1e4eb2b 100644 --- a/src/services/API.js +++ b/src/services/API.js @@ -21,7 +21,10 @@ apiClient.interceptors.response.use( return response; }, function (error) { - if (error.response.status === 401 || error.response.status === 419) { + if ( + error.response && + (error.response.status === 401 || error.response.status === 419) + ) { store.dispatch("auth/logout"); } return Promise.reject(error); diff --git a/src/services/AuthService.js b/src/services/AuthService.js index e88f72a..62c1c21 100644 --- a/src/services/AuthService.js +++ b/src/services/AuthService.js @@ -14,7 +14,10 @@ authClient.interceptors.response.use( return response; }, function (error) { - if (error.response.status === 401 || error.response.status === 419) { + if ( + error.response && + (error.response.status === 401 || error.response.status === 419) + ) { store.dispatch("auth/logout"); } return Promise.reject(error);