async function checkToken(token) {
const result = await superagent
.post(`${config.serviceUrl}/check_token`)
.send({token});
return result.body;
}
Default options if this call will return 401 throws an Exception, which is not what i expect. API i call is using HTTP status messages also as body to give information back and i just need the body part.
Response with http status 401 is
{
"data": null,
"error": {
"code": "INVALID_TOKEN",
"message": "Token is not valid"
}
}
And currently, to get this, I need to wrap all superagent calls with try...catch
async function checkToken(token) {
let result = null;
try {
result = await superagent
.post(`${config.serviceUrl}/check_token`)
.send({token});
} catch (e) {
result = e.response;
}
return result.body;
}
Any way to have the 1st sample working and returning JSON w/o looking at HTTP status?