mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 14:12:40 +00:00
Add support for custom HBErrorCodes
This commit is contained in:
@@ -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 <UIPage brew={{ title: 'Crit Fail!' }}>
|
||||
<div className='dataGroup'>
|
||||
|
||||
@@ -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*.`
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user