Home > Blockchain >  hide 503 error in vue2 app with axios http requests
hide 503 error in vue2 app with axios http requests

Time:11-27

I have a Vue 2.0 app which interacts with backend via axios httpRequest. From time to time when server is busy I get a :

xhr.js:220 POST https://backend/api?param=myparam 503 In console.

I’d like to hide it.

I’ve tried using the following configuration as per (https://axios-http.com/docs/handling_errors): (btw I’m resolving concurrently an array of promises) `

// append Promise to promiseArray
promiseArray.push(
     axios.get(“/api?param=myparam”,
          {
           validateStatus: () => true
          }
)


// Concurrency
Promise.all(promiseArray)

But still have the 503 error in console …

CodePudding user response:

I don't know axios specfically, so my answer could not be the best one.

Looking at the docs you linked, it seems that you could write this to avoid the 503 status code to throw an error:

axios.get(“/api?param=myparam”,
          {
           validateStatus: status => status != 503
          }

As a more aggressive alternative, have you tried wrapping your Promise.all in a try..catch block? Like this:

try {
  Promise.all(promiseArray)
} catch(err) {
  // Here you can manage your error, it's in the "err" variable
  // I suggest to handle this error in some way, as there could not only be an 503 error
} 
  • Related