diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index bb590285..d6c93292 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -246,7 +246,7 @@ const getGun = () => { const getUser = () => { if (!user.is) { logger.warn('called getUser() without being authed') - throw new Error('NOT_AUTH') + throw new Error(Constants.ErrorCode.NOT_AUTH) } return user } diff --git a/services/gunDB/contact-api/streams/lastSentReqID.js b/services/gunDB/contact-api/streams/lastSentReqID.js index 01cce49d..431adb58 100644 --- a/services/gunDB/contact-api/streams/lastSentReqID.js +++ b/services/gunDB/contact-api/streams/lastSentReqID.js @@ -1,5 +1,6 @@ /** @format */ const logger = require('winston') +const { Constants } = require('shock-common') const Key = require('../key') @@ -23,7 +24,7 @@ const onLastSentReqIDs = cb => { const user = require('../../Mediator').getUser() if (!user.is) { logger.warn('lastSentReqID() -> tried to sub without authing') - throw new Error('NOT_AUTH') + throw new Error(Constants.ErrorCode.NOT_AUTH) } user.get(Key.USER_TO_LAST_REQUEST_SENT).open(data => { diff --git a/services/gunDB/contact-api/utils/index.js b/services/gunDB/contact-api/utils/index.js index a35bbea5..bafa0378 100644 --- a/services/gunDB/contact-api/utils/index.js +++ b/services/gunDB/contact-api/utils/index.js @@ -129,7 +129,7 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => { } catch (e) { logger.error(e) logger.info(JSON.stringify(e)) - if (e.message === 'NOT_AUTH') { + if (e.message === Constants.ErrorCode.NOT_AUTH) { throw e } } @@ -159,7 +159,7 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => { } } catch (e) { logger.error(e) - if (e.message === 'NOT_AUTH') { + if (e.message === Constants.ErrorCode.NOT_AUTH) { throw e } } @@ -189,7 +189,7 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => { } } catch (e) { logger.error(e) - if (e.message === 'NOT_AUTH') { + if (e.message === Constants.ErrorCode.NOT_AUTH) { throw e } } diff --git a/src/routes.js b/src/routes.js index eab259dd..3701a119 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1944,9 +1944,11 @@ module.exports = async ( } catch (err) { logger.info('Error in Chats poll:') logger.error(err) - res.status(err.message === 'NON_AUTH' ? 401 : 500).json({ - errorMessage: typeof err === 'string' ? err : err.message - }) + res + .status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500) + .json({ + errorMessage: typeof err === 'string' ? err : err.message + }) } }) @@ -1966,9 +1968,11 @@ module.exports = async ( } catch (err) { logger.info('Error in Avatar poll:') logger.error(err) - res.status(err.message === 'NON_AUTH' ? 401 : 500).json({ - errorMessage: typeof err === 'string' ? err : err.message - }) + res + .status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500) + .json({ + errorMessage: typeof err === 'string' ? err : err.message + }) } }) @@ -1988,9 +1992,11 @@ module.exports = async ( } catch (err) { logger.info('Error in Display Name poll:') logger.error(err) - res.status(err.message === 'NON_AUTH' ? 401 : 500).json({ - errorMessage: typeof err === 'string' ? err : err.message - }) + res + .status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500) + .json({ + errorMessage: typeof err === 'string' ? err : err.message + }) } }) @@ -2007,9 +2013,11 @@ module.exports = async ( } catch (err) { logger.info('Error in Handshake Address poll:') logger.error(err) - res.status(err.message === 'NON_AUTH' ? 401 : 500).json({ - errorMessage: typeof err === 'string' ? err : err.message - }) + res + .status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500) + .json({ + errorMessage: typeof err === 'string' ? err : err.message + }) } }) @@ -2024,9 +2032,11 @@ module.exports = async ( } catch (err) { logger.info('Error in BIO poll:') logger.error(err) - res.status(err.message === 'NON_AUTH' ? 401 : 500).json({ - errorMessage: typeof err === 'string' ? err : err.message - }) + res + .status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500) + .json({ + errorMessage: typeof err === 'string' ? err : err.message + }) } }) ////////////////////////////////////////////////////////////////////////////////