better error logging for AF

This commit is contained in:
fenwick67 2024-10-13 11:09:36 -04:00
parent 3ad736116d
commit f1b36dc8d4
2 changed files with 12 additions and 4 deletions

View File

@ -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);
})
})

View File

@ -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
}