From 64b792c6450e005229886f0f7a7dcb3cd0ffdba7 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Wed, 18 Dec 2024 13:02:14 -0500 Subject: [PATCH] Fix case where no stub is found When retrieving a Google Brew with no stub yet, if the user is not logged in or has expired credentials, we enter this error handler. However, the error message itself tries to send a list of authors. If there was no stub, we crash here with a 500 error. This adds conditional operator to any stub value so we can send the actual "not logged in" error in case of no stub. --- server/homebrew.api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 159c08b47..7bf10f38d 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -111,7 +111,7 @@ const api = { const isInvited = stub?.invitedAuthors?.includes(req.account?.username); if(accessType === 'edit' && !(isOwner || isAuthor || isInvited)) { - const accessError = { name: 'Access Error', status: 401, authors: stub.authors, brewTitle: stub.title, shareId: stub.shareId }; + const accessError = { name: 'Access Error', status: 401, authors: stub?.authors, brewTitle: stub?.title, shareId: stub?.shareId }; if(req.account) throw { ...accessError, message: 'User is not an Author', HBErrorCode: '03' }; else @@ -119,7 +119,7 @@ const api = { } if(stub?.lock?.locked && accessType != 'edit') { - throw { HBErrorCode: '51', code: stub.lock.code, message: stub.lock.shareMessage, brewId: stub.shareId, brewTitle: stub.title }; + throw { HBErrorCode: '51', code: stub?.lock.code, message: stub?.lock.shareMessage, brewId: stub?.shareId, brewTitle: stub?.title }; } // If there is a google id, try to find the google brew