@prairielearn/sentry 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/express.js +1 -1
- package/dist/express.js.map +1 -1
- package/package.json +5 -5
- package/src/express.ts +1 -1
package/CHANGELOG.md
CHANGED
package/dist/express.js
CHANGED
|
@@ -68,7 +68,7 @@ export function setupExpressErrorHandler(app, options) {
|
|
|
68
68
|
}
|
|
69
69
|
function getStatusCodeFromResponse(error) {
|
|
70
70
|
const statusCode = error.status || error.statusCode || error.status_code || error.output?.statusCode;
|
|
71
|
-
return statusCode ? parseInt(statusCode
|
|
71
|
+
return statusCode ? Number.parseInt(statusCode) : 500;
|
|
72
72
|
}
|
|
73
73
|
/** Returns true if response code is internal server error */
|
|
74
74
|
function defaultShouldHandleError(error) {
|
package/dist/express.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,+EAA+E;AAC/E,8EAA8E;AAC9E,oEAAoE;AACpE,EAAE;AACF,0EAA0E;AAC1E,iCAAiC;AACjC,EAAE;AACF,yDAAyD;AACzD,iJAAiJ;AAIjJ,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAgCpD;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA+B;IACjE,OAAO,SAAS,qBAAqB,CACnC,KAAsB,EACtB,OAA6B,EAC7B,GAAwB,EACxB,IAAsC;QAEtC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;QAC5D,iFAAiF;QACjF,oGAAoG;QACpG,iBAAiB,EAAE,CAAC,wBAAwB,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC;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CAAC;IACT,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,wBAAwB,CACtC,GAAiF,EACjF,OAA+B;IAE/B,GAAG,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC,CAAC;IACjC,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;IACtC,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,yBAAyB,CAAC,KAAsB;IACvD,MAAM,UAAU,GACd,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC;IACpF,OAAO,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAoB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AAClE,CAAC;AAED,6DAA6D;AAC7D,SAAS,wBAAwB,CAAC,KAAsB;IACtD,MAAM,MAAM,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;IAChD,OAAO,MAAM,IAAI,GAAG,CAAC;AACvB,CAAC","sourcesContent":["/* eslint-disable jsdoc/check-param-names */\n// This is a fork of Sentry's Express integration from `@sentry/node`that's not\n// available in the `@sentry/node-core` package`. It has been lightly modified\n// to remove unused code and conform to PrairieLearn's coding style.\n//\n// See this package's `README.md` for more information about why we aren't\n// using `@sentry/node` directly.\n//\n// This was forked from the following file on 2025-07-30:\n// https://github.com/getsentry/sentry-javascript/blob/12ac49a9956fd1b64b3f8ad4b2b8f1da426a1efd/packages/node/src/integrations/tracing/express.ts\n\nimport type * as http from 'node:http';\n\nimport { captureException, getIsolationScope, httpRequestToRequestData } from '@sentry/core';\nimport { ensureIsWrapped } from '@sentry/node-core';\n\ninterface MiddlewareError extends Error {\n status?: number | string;\n statusCode?: number | string;\n status_code?: number | string;\n output?: {\n statusCode?: number | string;\n };\n}\n\ntype ExpressMiddleware = (\n req: http.IncomingMessage,\n res: http.ServerResponse,\n next: () => void,\n) => void;\n\ntype ExpressErrorMiddleware = (\n error: MiddlewareError,\n req: http.IncomingMessage,\n res: http.ServerResponse,\n next: (error: MiddlewareError) => void,\n) => void;\n\ninterface ExpressHandlerOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n * @param error Captured middleware error\n */\n shouldHandleError?(error: MiddlewareError): boolean;\n}\n\n/**\n * An Express-compatible error handler.\n */\nexport function expressErrorHandler(options?: ExpressHandlerOptions): ExpressErrorMiddleware {\n return function sentryErrorMiddleware(\n error: MiddlewareError,\n request: http.IncomingMessage,\n res: http.ServerResponse,\n next: (error: MiddlewareError) => void,\n ): void {\n const normalizedRequest = httpRequestToRequestData(request);\n // Ensure we use the express-enhanced request here, instead of the plain HTTP one\n // When an error happens, the `expressRequestHandler` middleware does not run, so we set it here too\n getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });\n\n const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;\n\n if (shouldHandleError(error)) {\n const eventId = captureException(error, {\n mechanism: { type: 'middleware', handled: false },\n });\n (res as { sentry?: string }).sentry = eventId;\n }\n\n next(error);\n };\n}\n\nfunction expressRequestHandler(): ExpressMiddleware {\n return function sentryRequestMiddleware(\n request: http.IncomingMessage,\n _res: http.ServerResponse,\n next: () => void,\n ): void {\n const normalizedRequest = httpRequestToRequestData(request);\n // Ensure we use the express-enhanced request here, instead of the plain HTTP one\n getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });\n\n next();\n };\n}\n\n/**\n * Add an Express error handler to capture errors to Sentry.\n *\n * The error handler must be before any other middleware and after all controllers.\n *\n * @param app The Express instances\n * @param options {ExpressHandlerOptions} Configuration options for the handler\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n * const express = require(\"express\");\n *\n * const app = express();\n *\n * // Add your routes, etc.\n *\n * // Add this after all routes,\n * // but before any and other error-handling middlewares are defined\n * Sentry.setupExpressErrorHandler(app);\n *\n * app.listen(3000);\n * ```\n */\nexport function setupExpressErrorHandler(\n app: { use: (middleware: ExpressMiddleware | ExpressErrorMiddleware) => unknown },\n options?: ExpressHandlerOptions,\n): void {\n app.use(expressRequestHandler());\n app.use(expressErrorHandler(options));\n ensureIsWrapped(app.use, 'express');\n}\n\nfunction getStatusCodeFromResponse(error: MiddlewareError): number {\n const statusCode =\n error.status || error.statusCode || error.status_code || error.output?.statusCode;\n return statusCode ? Number.parseInt(statusCode as string) : 500;\n}\n\n/** Returns true if response code is internal server error */\nfunction defaultShouldHandleError(error: MiddlewareError): boolean {\n const status = getStatusCodeFromResponse(error);\n return status >= 500;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prairielearn/sentry",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"dev": "tsc --watch --preserveWatchOutput"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@sentry/core": "^10.
|
|
17
|
-
"@sentry/node-core": "^10.
|
|
16
|
+
"@sentry/core": "^10.8.0",
|
|
17
|
+
"@sentry/node-core": "^10.8.0",
|
|
18
18
|
"execa": "^9.6.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@prairielearn/tsconfig": "^0.0.0",
|
|
22
|
-
"@types/node": "^22.
|
|
23
|
-
"tsx": "^4.20.
|
|
22
|
+
"@types/node": "^22.18.0",
|
|
23
|
+
"tsx": "^4.20.5",
|
|
24
24
|
"typescript": "^5.9.2"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/src/express.ts
CHANGED
|
@@ -122,7 +122,7 @@ export function setupExpressErrorHandler(
|
|
|
122
122
|
function getStatusCodeFromResponse(error: MiddlewareError): number {
|
|
123
123
|
const statusCode =
|
|
124
124
|
error.status || error.statusCode || error.status_code || error.output?.statusCode;
|
|
125
|
-
return statusCode ? parseInt(statusCode as string
|
|
125
|
+
return statusCode ? Number.parseInt(statusCode as string) : 500;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/** Returns true if response code is internal server error */
|