-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(express): Allow to pass options to
setupExpressErrorHandler
(#…
…12952) Allows to pass this through to the underlying `expressErrorHandler`. See #12715 (reply in thread)
- Loading branch information
Showing
4 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
dev-packages/node-integration-tests/suites/express/setupExpressErrorHandler/server.js
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,33 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
transport: loggingTransport, | ||
}); | ||
|
||
// express must be required after Sentry is initialized | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const { startExpressServerAndSendPortToRunner } = require('@sentry-internal/node-integration-tests'); | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
|
||
app.get('/test1', (_req, _res) => { | ||
throw new Error('error_1'); | ||
}); | ||
|
||
app.get('/test2', (_req, _res) => { | ||
throw new Error('error_2'); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app, { | ||
shouldHandleError: error => { | ||
return error.message === 'error_2'; | ||
}, | ||
}); | ||
|
||
startExpressServerAndSendPortToRunner(app); |
30 changes: 30 additions & 0 deletions
30
dev-packages/node-integration-tests/suites/express/setupExpressErrorHandler/test.ts
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,30 @@ | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
describe('express setupExpressErrorHandler', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
describe('CJS', () => { | ||
test('allows to pass options to setupExpressErrorHandler', done => { | ||
const runner = createRunner(__dirname, 'server.js') | ||
.expect({ | ||
event: { | ||
exception: { | ||
values: [ | ||
{ | ||
value: 'error_2', | ||
}, | ||
], | ||
}, | ||
}, | ||
}) | ||
.start(done); | ||
|
||
// this error is filtered & ignored | ||
expect(() => runner.makeRequest('get', '/test1')).rejects.toThrow(); | ||
// this error is actually captured | ||
expect(() => runner.makeRequest('get', '/test2')).rejects.toThrow(); | ||
}); | ||
}); | ||
}); |
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