Skip to content

Commit

Permalink
Merge branch 'main' into renovate/lock-file-maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Jan 15, 2025
2 parents 2ac6214 + 1a6839b commit 67f5776
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 67f5776

Please sign in to comment.