better error logging for AF
This commit is contained in:
parent
3ad736116d
commit
f1b36dc8d4
4
index.js
4
index.js
|
@ -110,8 +110,8 @@ app.get('/apiv2/feed',cors(),logger,function(req,res){
|
|||
res.send(data);
|
||||
}).catch((er)=>{
|
||||
res.status(500);
|
||||
res.send(errorPage(500,null,{theme:opts.theme,size:opts.size}));
|
||||
// TODO log the error
|
||||
res.send(errorPage(500,er.toString(),{theme:opts.theme,size:opts.size}));
|
||||
// log the error
|
||||
console.error(er,er.stack);
|
||||
})
|
||||
})
|
||||
|
|
12
lib/apGet.js
12
lib/apGet.js
|
@ -66,12 +66,20 @@ module.exports = async function apGet(url,ttl) {
|
|||
|
||||
console.log("axios request info: \n"+JSON.stringify(axiosOpts,null,2))
|
||||
|
||||
let response = await axios(axiosOpts)
|
||||
let response
|
||||
try {
|
||||
response = await axios(axiosOpts)
|
||||
} catch(e){
|
||||
if (e.response){
|
||||
throw new Error(`got ${e.response.status} response from server: `+JSON.stringify(e.response.data))
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
// axios would have rejected if we got a 4xx or 5xx or not json
|
||||
cache.set(url, response.data, {
|
||||
ttl: ttl || 24 * hour
|
||||
});
|
||||
return response.data
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue