mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 12:02:44 +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)=>{
|
app.use(async (err, req, res, next)=>{
|
||||||
err.originalUrl = req.originalUrl;
|
err.originalUrl = req.originalUrl;
|
||||||
console.error(err);
|
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;
|
const status = err.status || err.code || 500;
|
||||||
|
|
||||||
req.ogMeta = { ...defaultMetaTags,
|
req.ogMeta = { ...defaultMetaTags,
|
||||||
@@ -490,12 +498,6 @@ app.use(async (err, req, res, next)=>{
|
|||||||
};
|
};
|
||||||
req.customUrl= '/error';
|
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);
|
const page = await renderPage(req, res);
|
||||||
if(!page) return;
|
if(!page) return;
|
||||||
res.send(page);
|
res.send(page);
|
||||||
|
|||||||
Reference in New Issue
Block a user