Catch the network error in a Axios request

Posted on October 16, 2022

Here the ES6way, in async function, to catch an network error when using Axios:

import axios from 'axios'

let res = null

try{
  res = await axios(dataUrl)
    // do something the the response
}catch(e){
  console.log('err', e)
}

// do something after the fetch