0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-03 21:22:39 +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,39 +1,50 @@
const dedent = require('dedent-tabs').default; const dedent = require('dedent-tabs').default;
const errorIndex = () => { const errorIndex = ()=>{
return { return {
"404" : dedent` '00' : dedent`
## We can't find this brew in your Google Drive! ## An unknown error occurred!
This error tells us your file was saved on your Google Drive, but the link We aren't sure what happened, but our server wasn't able to find what you
you tried to open doesn't work anymore. The Homebrewery cannot delete files were looking for.`,
from your Google Drive on its own, so there are three most likely possibilities:
: '01' : dedent`
- **You may have accidentally deleted the Google Drive files.** Look on your Google Drive ## An error occurred while retrieving this brew from Google Drive!
and make sure the Homebrewery folder is still there, and that it holds your brews
as text files. Google reported an error while attempting to retrieve a brew from this link.`,
- **You may have changed the sharing settings for your files.** If the files
are still on Google Drive, change all of them to be shared *with everyone who has '02' : dedent`
the link* so the Homebrewery can access them. ## We can't find this brew in your Google Drive!
- **Your Google Account may be full**, or may be have been closed by
Google (for inactivity, violating some policy of theirs). Make sure you can still This error tells us your file was saved on your Google Drive, but the link
access your Google Drive normally and upload/download files to it. you tried to open doesn't work anymore. The Homebrewery cannot delete files
: from your Google Drive on its own, so there are three most likely possibilities:
If you can't find it, Google Drive usually puts your file in your Trash folder for :
30 days. Assuming you didn't empty the trash right after, it might be worth checking. - **You may have accidentally deleted the Google Drive files.** Look on your Google Drive
You can also look on the right side of the page while logged into Google Drive and and make sure the Homebrewery folder is still there, and that it holds your brews
look at the Activity tab. This can help you pin down the exact date the brew was as text files.
deleted and by whom. - **You may have changed the sharing settings for your files.** If the files
: are still on Google Drive, change all of them to be shared *with everyone who has
If you *still* can't find it, some people have had success asking Google to recover the link* so the Homebrewery can access them.
accidentally deleted files at this link: - **Your Google Account may be full**, or may be have been closed by
https://support.google.com/drive/answer/1716222?hl=en&ref_topic=7000946. Google (for inactivity, violating some policy of theirs). Make sure you can still
At the bottom of the page there is a button that says *Send yourself an Email* access your Google Drive normally and upload/download files to it.
and you will receive instructions on how to request the files be restored. :
: If you can't find it, Google Drive usually puts your file in your Trash folder for
Also note, if you prefer not to use your Google Drive for storage, you can always 30 days. Assuming you didn't empty the trash right after, it might be worth checking.
change the storage location of a brew by clicking the Google drive icon by the You can also look on the right side of the page while logged into Google Drive and
brew title and choosing *transfer my brew to/from Google Drive*.` look at the Activity tab. This can help you pin down the exact date the brew was
deleted and by whom.
:
If you *still* can't find it, some people have had success asking Google to recover
accidentally deleted files at this link:
https://support.google.com/drive/answer/1716222?hl=en&ref_topic=7000946.
At the bottom of the page there is a button that says *Send yourself an Email*
and you will receive instructions on how to request the files be restored.
:
Also note, if you prefer not to use your Google Drive for storage, you can always
change the storage location of a brew by clicking the Google drive icon by the
brew title and choosing *transfer my brew to/from Google Drive*.`
}; };
}; };

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;