mirror of
https://github.com/detleph/server.git
synced 2026-09-04 16:46:04 +02:00
Add basic error handling
+ Add express-async-errors package to handle async errors + Add ForwaradableError class (Base class for all project-specific errors) + Add defaultErrorHandler middleware which handles errors and sends info to the client
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
export default class ForwardableError extends Error {
|
||||
// If in different context
|
||||
private readonly __id = "CUSTOM_ERROR";
|
||||
|
||||
public readonly status: number;
|
||||
|
||||
constructor(status: number, message: string) {
|
||||
super(message);
|
||||
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
static isForwardableError(error: any): error is ForwardableError {
|
||||
return error.__id === "CUSTOM_ERROR";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user