-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into secret-versioning
- Loading branch information
Showing
35 changed files
with
1,640 additions
and
284 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ErrorRequestHandler } from "express"; | ||
|
||
import * as Sentry from '@sentry/node'; | ||
import { InternalServerError } from "../utils/errors"; | ||
import { getLogger } from "../utils/logger"; | ||
import RequestError, { LogLevel } from "../utils/requestError"; | ||
|
||
|
||
export const requestErrorHandler: ErrorRequestHandler = (error: RequestError|Error, req, res, next) => { | ||
if(res.headersSent) return next(); | ||
//TODO: Find better way to type check for error. In current setting you need to cast type to get the functions and variables from RequestError | ||
if(!(error instanceof RequestError)){ | ||
error = InternalServerError({context: {exception: error.message}, stack: error.stack}) | ||
getLogger('backend-main').log((<RequestError>error).levelName.toLowerCase(), (<RequestError>error).message) | ||
} | ||
|
||
//* Set Sentry user identification if req.user is populated | ||
if(req.user !== undefined && req.user !== null){ | ||
Sentry.setUser({ email: req.user.email }) | ||
} | ||
//* Only sent error to Sentry if LogLevel is one of the following level 'ERROR', 'EMERGENCY' or 'CRITICAL' | ||
//* with this we will eliminate false-positive errors like 'BadRequestError', 'UnauthorizedRequestError' and so on | ||
if([LogLevel.ERROR, LogLevel.EMERGENCY, LogLevel.CRITICAL].includes((<RequestError>error).level)){ | ||
Sentry.captureException(error) | ||
} | ||
|
||
res.status((<RequestError>error).statusCode).json((<RequestError>error).format(req)) | ||
next() | ||
} |
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
Oops, something went wrong.