0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-06 23:02:45 +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

@@ -23,7 +23,7 @@ const ErrorPage = createClass({
}, },
render : function(){ render : function(){
const errorText = ErrorIndex()[this.props.brew.status.toString()] || ''; const errorText = ErrorIndex()[this.props.brew.HBErrorCode.toString()] || '';
return <UIPage brew={{ title: 'Crit Fail!' }}> return <UIPage brew={{ title: 'Crit Fail!' }}>
<div className='dataGroup'> <div className='dataGroup'>

View File

@@ -1,8 +1,19 @@
const dedent = require('dedent-tabs').default; const dedent = require('dedent-tabs').default;
const errorIndex = () => { const errorIndex = ()=>{
return { return {
"404" : dedent` '00' : dedent`
## An unknown error occurred!
We aren't sure what happened, but our server wasn't able to find what you
were looking for.`,
'01' : dedent`
## An error occurred while retrieving this brew from Google Drive!
Google reported an error while attempting to retrieve a brew from this link.`,
'02' : dedent`
## We can't find this brew in your Google Drive! ## We can't find this brew in your Google Drive!
This error tells us your file was saved on your Google Drive, but the link This error tells us your file was saved on your Google Drive, but the link

View File

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

View File

@@ -58,8 +58,8 @@ const api = {
}); });
// Throw any error caught while attempting to retrieve Google brew. // Throw any error caught while attempting to retrieve Google brew.
if(googleError) { if(googleError) {
// console.log(googleError); const reason = googleError.errors[0].reason;
throw { ...new Error, ...googleError }; 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 // 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; stub = stub ? _.assign({ ...api.excludeStubProps(stub), stubbed: true }, api.excludeGoogleProps(googleBrew)) : googleBrew;