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

21 lines
596 B
TypeScript
Raw Normal View History

2020-12-29 04:05:39 +01:00
export class UnauthorizedError extends Error {
public inner: { message: string }
public data: { message: string; code: string; type: 'UnauthorizedError' }
2020-12-29 04:05:39 +01:00
constructor(code: string, error: { message: string }) {
2020-12-29 04:05:39 +01:00
super(error.message)
this.message = error.message
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'
}