forked from powerhouse-inc/switchboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added driveId exists middleware
- Loading branch information
Showing
8 changed files
with
101 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { CustomError } from "./CustomError"; | ||
|
||
export default class NotFoundError extends CustomError { | ||
private static readonly _statusCode = 404; | ||
private readonly _code: number; | ||
private readonly _logging: boolean; | ||
private readonly _context: { [key: string]: any }; | ||
|
||
constructor(params?: { code?: number, message?: string, logging?: boolean, context?: { [key: string]: any } }) { | ||
const { code, message, logging } = params || {}; | ||
|
||
super(message || "Not Found"); | ||
this._code = code || NotFoundError._statusCode; | ||
this._logging = logging || false; | ||
this._context = params?.context || {}; | ||
|
||
// Only because we are extending a built in class | ||
Object.setPrototypeOf(this, NotFoundError.prototype); | ||
} | ||
|
||
get errors() { | ||
return [{ message: this.message, context: this._context }]; | ||
} | ||
|
||
get statusCode() { | ||
return this._code; | ||
} | ||
|
||
get logging() { | ||
return this._logging; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { NextFunction, Request, Response } from "express"; | ||
import { getChildLogger } from "../logger"; | ||
import { CustomError } from "../errors/CustomError"; | ||
|
||
const logger = getChildLogger({ msgPrefix: 'Generic Error Handler', }); | ||
|
||
export const errorHandler = (err: Error, req: Request, res: Response, next: NextFunction) => { | ||
const errorId = (res as { sentry?: string }).sentry; | ||
err.cause = err.cause || 'Unknown'; | ||
logger.error(err, err.message, { errorId }); | ||
res.status(500).send({ errors: err.message, errorId }); | ||
export const errorHandler = (err: CustomError, req: Request, res: Response, next: NextFunction) => { | ||
const errorId = (res as { sentry?: string }).sentry; | ||
err.cause = err.cause || 'Unknown'; | ||
logger.error(err, err.message, { errorId }); | ||
res.status(err.statusCode ?? 500).send({ errors: err.message, errorId }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters