mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-01 19:32:42 +00:00
Move API call error handling
This commit is contained in:
@@ -474,6 +474,14 @@ const getPureError = (error)=>{
|
||||
app.use(async (err, req, res, next)=>{
|
||||
err.originalUrl = req.originalUrl;
|
||||
console.error(err);
|
||||
|
||||
if(err.originalUrl?.startsWith('/api/')) {
|
||||
// console.log('API error');
|
||||
res.status(err?.status || err?.response?.status || 500).send(err.message || err);
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log('non-API error');
|
||||
const status = err.status || err.code || 500;
|
||||
|
||||
req.ogMeta = { ...defaultMetaTags,
|
||||
@@ -490,12 +498,6 @@ app.use(async (err, req, res, next)=>{
|
||||
};
|
||||
req.customUrl= '/error';
|
||||
|
||||
if(req.originalUrl.startsWith('/api/')) {
|
||||
// console.log('api error');
|
||||
res.status(err?.status || err?.response?.status || 500).send(err.message || err);
|
||||
return;
|
||||
}
|
||||
|
||||
const page = await renderPage(req, res);
|
||||
if(!page) return;
|
||||
res.send(page);
|
||||
|
||||
Reference in New Issue
Block a user