mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 10:22:16 +00:00
fix(api): catch GB init errors on prod only (#59912)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
committed by
GitHub
parent
34ee68faa8
commit
3c822da243
@@ -1,6 +1,13 @@
|
||||
import Fastify, { type FastifyInstance } from 'fastify';
|
||||
import growthBook from './growth-book';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
jest.mock('../utils/env', () => ({
|
||||
...jest.requireActual('../utils/env'),
|
||||
// We're only interested in the production behaviour
|
||||
FREECODECAMP_NODE_ENV: 'production'
|
||||
}));
|
||||
|
||||
const captureException = jest.fn();
|
||||
|
||||
describe('growth-book', () => {
|
||||
|
||||
@@ -2,6 +2,8 @@ import { GrowthBook, Options } from '@growthbook/growthbook';
|
||||
import { FastifyPluginAsync } from 'fastify';
|
||||
import fp from 'fastify-plugin';
|
||||
|
||||
import { FREECODECAMP_NODE_ENV } from '../utils/env';
|
||||
|
||||
declare module 'fastify' {
|
||||
interface FastifyInstance {
|
||||
gb: GrowthBook;
|
||||
@@ -12,7 +14,7 @@ const growthBook: FastifyPluginAsync<Options> = async (fastify, options) => {
|
||||
const gb = new GrowthBook(options);
|
||||
const res = await gb.init({ timeout: 3000 });
|
||||
|
||||
if (res.error) {
|
||||
if (res.error && FREECODECAMP_NODE_ENV === 'production') {
|
||||
fastify.log.error(res.error, 'Failed to initialize GrowthBook');
|
||||
fastify.Sentry.captureException(res.error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user