From f175323221ae9d9d291250a3f2343437b1a53fc5 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 18:22:22 +1200 Subject: [PATCH] Use common error object to reduce DRY --- server/homebrew.api.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 3fbe696e9..4c4f10705 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -68,10 +68,11 @@ const api = { const isAuthor = stub?.authors?.includes(req.account?.username); const isInvited = stub?.invitedAuthors?.includes(req.account?.username); if(accessType === 'edit' && (authorsExist && !(isAuthor || isInvited))) { + const accessError = { name: 'Access Error', status: 401 }; if(req.account){ - throw { name: 'Access Error', message: 'User is not an Author', status: 401, HBErrorCode: '03', authors: stub.authors }; + throw { ...accessError, message: 'User is not an Author', HBErrorCode: '03', authors: stub.authors }; } - throw { name: 'Access Error', message: 'User is not logged in', status: 401, HBErrorCode: '04' }; + throw { ...accessError, message: 'User is not logged in', HBErrorCode: '04' }; } // If after all of that we still don't have a brew, throw an exception