From 408b9dcc64bea70d8a6ad25ef121c20c2aa9f252 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Wed, 16 Oct 2019 22:30:29 +0200 Subject: [PATCH] Fix displaying error message when there is no error response --- src/utils/request.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/utils/request.js b/src/utils/request.js index bbed6501..51e74601 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -10,14 +10,19 @@ const service = axios.create({ service.interceptors.response.use( response => response, error => { + let errorMessage console.log(`Error ${error}`) - console.log(error.response.data) - // If there's an "error" property in the json, use it - const edata = error.response.data.error ? error.response.data.error : error.response.data + if (error.response) { + // If there's an "error" property in the json, use it + const edata = error.response.data.error ? error.response.data.error : error.response.data + errorMessage = `${error.message} - ${edata}` + } else { + errorMessage = error + } Message({ - message: `${error.message} - ${edata}`, + message: errorMessage, type: 'error', duration: 5 * 1000 })