Skip to content

Commit

Permalink
fix(instrumentation-fastify): add missing module export (#2633)
Browse files Browse the repository at this point in the history
Co-authored-by: Marc Pichler <[email protected]>
  • Loading branch information
tsmithhisler and pichlermarc authored Jan 15, 2025
1 parent bda9632 commit 1a6839b
Show file tree
Hide file tree
Showing 2 changed files with 16 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 | undefined;
}): () => FastifyInstance {
const instrumentation = this;

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

if (moduleExports.errorCodes !== undefined) {
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,15 @@ describe('fastify', () => {
},
});
});

it('should expose errorCodes', async function () {
// errorCodes was added in v4.8.0
// ref: https://github.com/fastify/fastify/compare/v4.7.0...v4.8.0
if (semver.lt(fastifyVersion, '4.8.0')) {
this.skip();
}
assert.ok(Fastify.errorCodes);
assert.strictEqual(typeof Fastify.errorCodes, 'object');
assert.ok('FST_ERR_NOT_FOUND' in Fastify.errorCodes);
});
});

0 comments on commit 1a6839b

Please sign in to comment.