authenzify
Version:
server to manage authentication authorization of users and more
38 lines (31 loc) • 813 B
JavaScript
import httpStatus from 'http-status'
const DEFAULT_ERROR = {
httpStatusCode: httpStatus.INTERNAL_SERVER_ERROR,
code: 'UNKNOWN',
httpStatusText: httpStatus[httpStatus.INTERNAL_SERVER_ERROR],
}
class HttpError extends Error {
code
description
httpStatusCode
httpStatusText
constructor({
code,
description,
httpStatusCode,
httpStatusText,
} = DEFAULT_ERROR) {
super(`${code || httpStatus[httpStatusCode]}`)
this.code = code
this.description = description
this.httpStatusCode = httpStatusCode
this.httpStatusText = httpStatusText
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor)
}
}
static isInstanceOf(instance) {
return instance instanceof HttpError
}
}
export default HttpError