From e5ef0aedd37f6b10cea9de7edf3c31b1eeb5f0ec Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 17:10:25 +1200 Subject: [PATCH] Pass all error properties to message generator --- client/homebrew/pages/errorPage/errorPage.jsx | 2 +- client/homebrew/pages/errorPage/errors/errorIndex.js | 11 +++++++++-- server/app.js | 1 + server/homebrew.api.js | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/homebrew/pages/errorPage/errorPage.jsx b/client/homebrew/pages/errorPage/errorPage.jsx index bc01887d1..33da05017 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.HBErrorCode.toString()] || ''; + const errorText = ErrorIndex(this.props)[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 6700c8de0..324b2f6d0 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -1,6 +1,6 @@ const dedent = require('dedent-tabs').default; -const errorIndex = ()=>{ +const errorIndex = (props)=>{ return { '00' : dedent` ## An unknown error occurred! @@ -49,7 +49,14 @@ const errorIndex = ()=>{ '03' : dedent` ## The current logged in user does not have editor access to this brew. - If you believe you should have access to this brew, ask the file owner to invite you as an author by opening the brew, viewing the Properties tab, and adding your username to the "invited authors" list. You can then try to access this document again.`, + If you believe you should have access to this brew, ask the file owner to invite you + as an author by opening the brew, viewing the Properties tab, and adding your username + to the "invited authors" list. You can then try to access this document again. + + Current Authors: + + ${props.brew.authors?.map((author)=>{return `- ${author}`;}).join('\n') || 'Unable to list authors'} + `, '04' : dedent` ## No Homebrewery document could be found. diff --git a/server/app.js b/server/app.js index 9861f2c5a..901349d97 100644 --- a/server/app.js +++ b/server/app.js @@ -473,6 +473,7 @@ app.use(async (err, req, res, next)=>{ description : 'Something went wrong!' }; req.brew = { + ...err, title : 'Error - Something went wrong!', text : err.errors?.map((error)=>{return error.message;}).join('\n\n') || err.message || 'Unknown error!', status : status, diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 978fc1350..7107cfbe3 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -68,7 +68,7 @@ const api = { const isAuthor = stub?.authors?.includes(req.account?.username); const isInvited = stub?.invitedAuthors?.includes(req.account?.username); if(accessType === 'edit' && (authorsExist && !(isAuthor || isInvited))) { - throw { name: 'Access Error', message: 'User is not an Author', status: 401, HBErrorCode: '03' }; + throw { name: 'Access Error', message: 'User is not an Author', status: 401, HBErrorCode: '03', authors: stub.authors }; } // If after all of that we still don't have a brew, throw an exception