0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 14:12:40 +00:00

Additional info in errors

This commit is contained in:
G.Ambatte
2023-06-25 20:39:36 +12:00
parent 04eb7d0556
commit fa38d5c892
2 changed files with 26 additions and 6 deletions

View File

@@ -4,17 +4,20 @@ const loginUrl = 'https://www.naturalcrit.com/login';
const errorIndex = (props)=>{
return {
// Default catch all
'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.`,
// General Google load error
'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.`,
// Google Drive - 404 : brew deleted or access denied
'02' : dedent`
## We can't find this brew in your Google Drive!
@@ -48,6 +51,7 @@ const errorIndex = (props)=>{
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*.`,
// User is not Authors list
'03' : dedent`
## The current logged in user does not have editor access to this brew.
@@ -62,30 +66,46 @@ const errorIndex = (props)=>{
${props.brew.authors?.map((author)=>{return `- ${author}`;}).join('\n') || 'Unable to list authors'}
`,
// User is not logged in
'04' : dedent`
## Not logged in
User is not logged in. Please log in [here](${loginUrl}).`,
// Brew load error
'05' : dedent`
## No Homebrewery document could be found.
The server could not locate the Homebrewery document.`,
The server could not locate the Homebrewery document.
**Requested access:** ${props.brew.accessType}
**Brew ID:** ${props.brew.brewId}
`,
// Brew save error
'06' : dedent`
## Unable to save Homebrewery document.
An error occurred wil attempting to save the Homebrewery document.`,
// Brew delete error
'07' : dedent`
## Unable to delete Homebrewery document.
An error occurred while attempting to remove the Homebrewery document.`,
An error occurred while attempting to remove the Homebrewery document.
**Brew ID:** ${props.brew.brewId}
`,
// Author delete error
'08' : dedent`
## Unable to remove user from Homebrewery document.
An error occurred while attempting to remove the current user from the Homebrewery document author list!`,
An error occurred while attempting to remove the user from the Homebrewery document author list!
**Brew ID:** ${props.brew.brewId}
`,
};
};

View File

@@ -77,7 +77,7 @@ const api = {
// If after all of that we still don't have a brew, throw an exception
if(!stub && !stubOnly) {
throw { name: 'BrewLoad Error', message: 'Brew not found', status: 404, HBErrorCode: '05' };
throw { name: 'BrewLoad Error', message: 'Brew not found', status: 404, HBErrorCode: '05', accessType: accessType, brewId: id };
}
// Clean up brew: fill in missing fields with defaults / fix old invalid values
@@ -313,7 +313,7 @@ const api = {
await HomebrewModel.deleteOne({ _id: brew._id })
.catch((err)=>{
console.error(err);
throw { name: 'BrewDelete Error', message: 'Error while removing', status: 500, HBErrorCode: '07' };
throw { name: 'BrewDelete Error', message: 'Error while removing', status: 500, HBErrorCode: '07', brewId: brew._id };
});
} else {
if(shouldDeleteGoogleBrew) {
@@ -325,7 +325,7 @@ const api = {
brew.markModified('authors'); //Mongo will not properly update arrays without markModified()
await brew.save()
.catch((err)=>{
throw { name: 'BrewAuthorDelete Error', message: err, status: 500, HBErrorCode: '08' };
throw { name: 'BrewAuthorDelete Error', message: err, status: 500, HBErrorCode: '08', brewId: brew._id };
});
}
}