0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 16:22:44 +00:00

Add support for custom HBErrorCodes

This commit is contained in:
Trevor Buckner
2023-06-24 02:57:03 -04:00
parent 6353341738
commit f6c5354ce0
4 changed files with 54 additions and 41 deletions

View File

@@ -413,7 +413,7 @@ if(isLocalEnvironment){
//Render the page
const templateFn = require('./../client/template.js');
const renderPage = async (req, res) => {
const renderPage = async (req, res)=>{
// Create configuration object
const configuration = {
local : isLocalEnvironment,
@@ -468,14 +468,16 @@ app.use(async (err, req, res, next)=>{
const status = err.status || err.code || 500;
console.error(err);
req.ogMeta = {...defaultMetaTags,
req.ogMeta = { ...defaultMetaTags,
title : 'Error Page',
description : 'Something went wrong!'
};
req.brew = {
title : 'Error - Something went wrong!',
text : err.errors?.map((error)=>{return error.message;}).join('\n\n') || err.message || 'Unknown error!',
status : status
title : 'Error - Something went wrong!',
text : err.errors?.map((error)=>{return error.message;}).join('\n\n') || err.message || 'Unknown error!',
status : status,
HBErrorCode : err.HBErrorCode ?? '00',
pureError : getPureError(err)
};
req.customUrl= '/error';

View File

@@ -58,8 +58,8 @@ const api = {
});
// Throw any error caught while attempting to retrieve Google brew.
if(googleError) {
// console.log(googleError);
throw { ...new Error, ...googleError };
const reason = googleError.errors[0].reason;
throw { ...Error, ...googleError, HBErrorCode: reason == 'notFound' ? '02' : '01' };
}
// Combine the Homebrewery stub with the google brew, or if the stub doesn't exist just use the google brew
stub = stub ? _.assign({ ...api.excludeStubProps(stub), stubbed: true }, api.excludeGoogleProps(googleBrew)) : googleBrew;