0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +00:00

Use common error object to reduce DRY

This commit is contained in:
G.Ambatte
2023-06-25 18:22:22 +12:00
parent 9f4de3c66e
commit f175323221

View File

@@ -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