Add error handling for InvalidError

This commit is contained in:
Alasdair Smith 2018-10-04 10:36:10 +01:00
parent e99165b475
commit bf60fe7f6c
2 changed files with 12 additions and 0 deletions

View file

@ -25,6 +25,10 @@ module.exports = ErrorController =
else if error instanceof Errors.TooManyRequestsError
logger.warn {err: error, url: req.url}, "too many requests error"
res.sendStatus(429)
else if error instanceof Errors.InvalidError
logger.warn {err: error, url: req.url}, "invalid error"
res.status(400)
res.send(error.message)
else if error instanceof Errors.InvalidNameError
logger.warn {err: error, url: req.url}, "invalid name error"
res.status(400)

View file

@ -82,6 +82,13 @@ EmailExistsError = (message) ->
return error
EmailExistsError.prototype.__proto__ = Error.prototype
InvalidError = (message) ->
error = new Error(message)
error.name = "InvalidError"
error.__proto__ = InvalidError.prototype
return error
InvalidError.prototype.__proto__ = Error.prototype
module.exports = Errors =
NotFoundError: NotFoundError
ServiceNotConfiguredError: ServiceNotConfiguredError
@ -95,3 +102,4 @@ module.exports = Errors =
V1ConnectionError: V1ConnectionError
UnconfirmedEmailError: UnconfirmedEmailError
EmailExistsError: EmailExistsError
InvalidError: InvalidError