Skip to content

setupKoaErrorHandler doesn't preserve the error status code and message in the response #12517

Closed
@maximedupre

Description

@maximedupre

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.9.2

Framework Version

"@sentry/node": "^8.9.2"

Link to Sentry event

No response

SDK Setup

init({
    dsn: '___DSN',
    tracesSampleRate: 0.1,
    profilesSampleRate: 1.0,
    normalizeDepth: 11,
    integrations: [nodeProfilingIntegration],
    environment: EnvVariablesUtility.NODE_ENV,
    enabled: EnvVariablesUtility.NODE_ENV !== 'local',
    beforeSend(event, hint) {
        const error: any = hint.originalException;

        if (error && error.expose) {
            return null;
        }

        return event;
    },
});

Steps to Reproduce

My middleware:

ctx.status = 201;
ctx.assert(isEmail.default(email), 400, 'The email is invalid');

Expected Result

Status code to be 400 with body text 'The email is invalid'

Actual Result

Status code is 201, body text is 'Created'

However, if I place setupKoaErrorHandler after I have defined all my middlewares, I get

Status code 400, no body

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions