Fix displaying error message when there is no error response
This commit is contained in:
parent
d47b3287bd
commit
408b9dcc64
1 changed files with 9 additions and 4 deletions
|
@ -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
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue