diff --git a/api/errors/HttpError.js b/api/errors/HttpError.js new file mode 100644 index 0000000..eabf73d --- /dev/null +++ b/api/errors/HttpError.js @@ -0,0 +1,16 @@ +class HttpError extends Error { + constructor (status, message, hint) { + super(message) + if (typeof status !== 'number') throw new Error('HttpError status must be an integer') + this.status = status + this.hint = hint || 'none' + } + send (res) { + return res.status(this.status).json({ + error: this.message, + hint: this.hint + }) + } +} + +module.exports = HttpError