for e.g.
(async() => {
let apiRes = null;
try {
apiRes = await axios.get('https://silex.edgeprop.my/api/v1/a');
} catch (err) {
console.error(err);
} finally {
console.log(apiRes);
}
})();
in finally
, apiRes
will return null.
Even when the api get a 404 response, there is still useful information in the response that I would like to use.
How can I use the error response in finally
when axios throws error.
err
? I can't see why you want it in thefinally
rather than thecatch
, but if you do, simply save it in thecatch
to a variable you can access in thefinally
. – Interpretationcatch
doesn't contain the api response. if I can get around this then your method would work ! – Sabu