respect NOT_AUTH constnat

This commit is contained in:
Daniel Lugo 2020-08-27 15:57:54 -04:00
parent 940fbfc96c
commit 90755ae0a1
4 changed files with 31 additions and 20 deletions

View file

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

View file

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

View file

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

View file

@ -1944,7 +1944,9 @@ module.exports = async (
} catch (err) {
logger.info('Error in Chats poll:')
logger.error(err)
res.status(err.message === 'NON_AUTH' ? 401 : 500).json({
res
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
.json({
errorMessage: typeof err === 'string' ? err : err.message
})
}
@ -1966,7 +1968,9 @@ module.exports = async (
} catch (err) {
logger.info('Error in Avatar poll:')
logger.error(err)
res.status(err.message === 'NON_AUTH' ? 401 : 500).json({
res
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
.json({
errorMessage: typeof err === 'string' ? err : err.message
})
}
@ -1988,7 +1992,9 @@ module.exports = async (
} catch (err) {
logger.info('Error in Display Name poll:')
logger.error(err)
res.status(err.message === 'NON_AUTH' ? 401 : 500).json({
res
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
.json({
errorMessage: typeof err === 'string' ? err : err.message
})
}
@ -2007,7 +2013,9 @@ module.exports = async (
} catch (err) {
logger.info('Error in Handshake Address poll:')
logger.error(err)
res.status(err.message === 'NON_AUTH' ? 401 : 500).json({
res
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
.json({
errorMessage: typeof err === 'string' ? err : err.message
})
}
@ -2024,7 +2032,9 @@ module.exports = async (
} catch (err) {
logger.info('Error in BIO poll:')
logger.error(err)
res.status(err.message === 'NON_AUTH' ? 401 : 500).json({
res
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
.json({
errorMessage: typeof err === 'string' ? err : err.message
})
}