Fix displaying error message when there is no error response

This commit is contained in:
Angelina Filippova 2019-10-16 22:30:29 +02:00
parent d47b3287bd
commit 408b9dcc64

View file

@ -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
})