22 lines
448 B
TypeScript
22 lines
448 B
TypeScript
import http from 'http'
|
|
|
|
export default class StatusError extends Error {
|
|
status: number
|
|
|
|
constructor(status = 500, message = http.STATUS_CODES[status] || 'Unknown Error', options?: Record<string, ANY>) {
|
|
super(message, options)
|
|
|
|
this.name = this.constructor.name
|
|
this.status = status
|
|
}
|
|
|
|
toJSON() {
|
|
return {
|
|
name: this.name,
|
|
message: this.message,
|
|
status: this.status,
|
|
stack: this.stack,
|
|
}
|
|
}
|
|
}
|