From f6c5354ce0e5ad34deb8deb5e30ee2b6dbd97f8f Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 24 Jun 2023 02:57:03 -0400 Subject: [PATCH] Add support for custom HBErrorCodes --- client/homebrew/pages/errorPage/errorPage.jsx | 2 +- .../pages/errorPage/errors/errorIndex.js | 77 +++++++++++-------- server/app.js | 12 +-- server/homebrew.api.js | 4 +- 4 files changed, 54 insertions(+), 41 deletions(-) diff --git a/client/homebrew/pages/errorPage/errorPage.jsx b/client/homebrew/pages/errorPage/errorPage.jsx index 4640a3ab4..bc01887d1 100644 --- a/client/homebrew/pages/errorPage/errorPage.jsx +++ b/client/homebrew/pages/errorPage/errorPage.jsx @@ -23,7 +23,7 @@ const ErrorPage = createClass({ }, render : function(){ - const errorText = ErrorIndex()[this.props.brew.status.toString()] || ''; + const errorText = ErrorIndex()[this.props.brew.HBErrorCode.toString()] || ''; return
diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index a97c3109a..c9be104fe 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -1,39 +1,50 @@ const dedent = require('dedent-tabs').default; -const errorIndex = () => { +const errorIndex = ()=>{ return { - "404" : dedent` - ## 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 - 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: - : - - **You may have accidentally deleted the Google Drive files.** Look on your Google Drive - and make sure the Homebrewery folder is still there, and that it holds your brews - as text files. - - **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 - the link* so the Homebrewery can access them. - - **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 - access your Google Drive normally and upload/download files to it. - : - 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 can also look on the right side of the page while logged into Google Drive and - 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*.` + '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! + + This error tells us your file was saved on your Google Drive, but the link + 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: + : + - **You may have accidentally deleted the Google Drive files.** Look on your Google Drive + and make sure the Homebrewery folder is still there, and that it holds your brews + as text files. + - **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 + the link* so the Homebrewery can access them. + - **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 + access your Google Drive normally and upload/download files to it. + : + 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 can also look on the right side of the page while logged into Google Drive and + 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*.` }; }; diff --git a/server/app.js b/server/app.js index 10f99ffaa..a30e3fdaf 100644 --- a/server/app.js +++ b/server/app.js @@ -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'; diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 2271466b8..516c1bc03 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -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;