UNPKG

@dvsa/appdev-api-common

Version:

Utils library for common API functionality

32 lines (31 loc) 983 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthError = void 0; const http_status_codes_1 = require("../api/http-status-codes"); class AuthError extends Error { statusCode; code; roleInfo; constructor(statusCode = http_status_codes_1.HttpStatus.UNAUTHORIZED, message = "Authorization failed", code = "UNAUTHORIZED", roleInfo = undefined) { super(message); this.statusCode = statusCode; this.code = code; this.name = "AuthError"; this.roleInfo = roleInfo ?? undefined; if (Error.captureStackTrace) { Error.captureStackTrace(this, AuthError); } } toJSON() { return { error: { name: this.name, code: this.code, message: this.message, statusCode: this.statusCode, roleInfo: this.roleInfo, }, }; } } exports.AuthError = AuthError;