This repository has been archived on 2024-11-11. You can view files and clone it, but cannot push or open issues or pull requests.
socketio-jwt/src/UnauthorizedError.ts
2022-04-07 10:14:52 +02:00

21 lines
599 B
TypeScript

export class UnauthorizedError extends Error {
public inner: { message: string }
public data: { message: string; code: string; type: 'UnauthorizedError' }
constructor(code: string, error: { message: string }) {
super(error.message)
this.name = 'UnauthorizedError'
this.inner = error
this.data = {
message: this.message,
code,
type: 'UnauthorizedError'
}
Object.setPrototypeOf(this, UnauthorizedError.prototype)
}
}
export const isUnauthorizedError = (error: any): error is UnauthorizedError => {
return error.data.type === 'UnauthorizedError'
}