Skip to content

Commit

Permalink
fix(instrumentation-fastify): add missing module export
Browse files Browse the repository at this point in the history
fastify v4.x+ exports an object named `errorCodes` as both a property of the default export and as a named export.

The export is documented at https://github.com/fastify/fastify/blob/4.x/docs/Reference/Errors.md?plain=1#L236.

This closes #2027.
  • Loading branch information
tsmithhisler committed Jan 8, 2025
1 parent 12ee8db commit 0e640e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type {
FastifyInstance,
FastifyRequest,
FastifyReply,
FastifyErrorCodes,
} from 'fastify';
import { hooksNamesToWrap } from './constants';
import {
Expand Down Expand Up @@ -185,6 +186,7 @@ export class FastifyInstrumentation extends InstrumentationBase<FastifyInstrumen

private _patchConstructor(moduleExports: {
fastify: () => FastifyInstance;
errorCodes: FastifyErrorCodes;
}): () => FastifyInstance {
const instrumentation = this;

Expand All @@ -198,6 +200,7 @@ export class FastifyInstrumentation extends InstrumentationBase<FastifyInstrumen
return app;
}

fastify.errorCodes = moduleExports.errorCodes
fastify.fastify = fastify;
fastify.default = fastify;
return fastify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,10 @@ describe('fastify', () => {
},
});
});

it('should expose errorCodes', async () => {
assert.ok(Fastify.errorCodes);
assert.strictEqual(typeof Fastify.errorCodes, 'object');
assert.ok('FST_ERR_NOT_FOUND' in Fastify.errorCodes);
})
});

0 comments on commit 0e640e9

Please sign in to comment.