Skip to content

feat(node): Add Koa error handler #11403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 5, 2024
Merged

Conversation

onurtemizkan
Copy link
Collaborator

Similarly to NestJS instrumentation, this PR adds:

  • setupKoaErrorHandler middleware to capture globally caught exceptions.
  • Koa end to end tests.

@onurtemizkan onurtemizkan force-pushed the onur/koa-error-handler branch 2 times, most recently from 22cdffb to 155b812 Compare April 3, 2024 14:20

router1.get('/test-outgoing-fetch/:id', async ctx => {
const id = ctx.params.id;
const response = await fetch(`http://localhost:3030/test-inbound-headers/${id}`);

Check failure

Code scanning / CodeQL

Server-side request forgery

The [URL](1) of this request depends on a [user-provided value](2).
Comment on lines +126 to +142
http
.request(url, httpRes => {
httpRes.on('data', chunk => {
data.push(chunk);
});
httpRes.on('error', error => {
resolve({ error: error.message, url });
});
httpRes.on('end', () => {
try {
const json = JSON.parse(Buffer.concat(data).toString());
resolve(json);
} catch {
resolve({ data: Buffer.concat(data).toString(), url });
}
});
})

Check failure

Code scanning / CodeQL

Server-side request forgery

The [URL](1) of this request depends on a [user-provided value](2).
@onurtemizkan onurtemizkan force-pushed the onur/koa-error-handler branch 2 times, most recently from fa98837 to 1801be1 Compare April 4, 2024 11:05
@onurtemizkan onurtemizkan marked this pull request as ready for review April 4, 2024 11:05
@onurtemizkan onurtemizkan requested a review from mydea April 4, 2024 11:05
@onurtemizkan onurtemizkan force-pushed the onur/koa-error-handler branch from 1801be1 to 0a74c10 Compare April 5, 2024 10:01
@AbhiPrasad AbhiPrasad self-requested a review April 5, 2024 14:18
@AbhiPrasad AbhiPrasad merged commit 3d82cdb into develop Apr 5, 2024
@AbhiPrasad AbhiPrasad deleted the onur/koa-error-handler branch April 5, 2024 14:56
cadesalaberry pushed a commit to cadesalaberry/sentry-javascript that referenced this pull request Apr 19, 2024
Similarly to NestJS instrumentation, this PR adds:

- `setupKoaErrorHandler` middleware to capture globally caught
exceptions.
- Koa end to end tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants