fix(api): use generic error handler with Sentry (#55176)

This commit is contained in:
Oliver Eyton-Williams
2024-06-13 19:18:16 +02:00
committed by GitHub
parent 6cfea56f12
commit 14df93bcef
5 changed files with 21 additions and 7 deletions
+17 -3
View File
@@ -105,9 +105,23 @@ export const build = async (
});
// NOTE: Awaited to ensure `.use` is registered on `fastify`
await fastify.register(express);
if (SENTRY_DSN) {
await fastify.register(fastifySentry, { dsn: SENTRY_DSN });
}
await fastify.register(fastifySentry, {
dsn: SENTRY_DSN,
// No need to initialize if DSN is not provided (e.g. in development and
// test environments)
skipInit: !!SENTRY_DSN,
errorResponse: (error, _request, reply) => {
if (reply.statusCode === 500) {
void reply.send({
message: 'flash.generic-error',
type: 'danger'
});
} else {
void reply.send(error);
}
}
});
await fastify.register(cors);
await fastify.register(cookies);
@@ -749,7 +749,7 @@
"flash": {
"honest-first": "To claim a certification, you must first agree to our academic honesty policy",
"really-weird": "Something really weird happened, if it happens again, please consider raising an issue on https://github.com/freeCodeCamp/freeCodeCamp/issues/new",
"not-right": "Something is not quite right. A report has been generated and the freeCodeCamp.org team have been notified",
"generic-error": "Something went wrong. Please try again in a moment or contact support@freecodecamp.org if the error persists.",
"went-wrong": "Something went wrong, please check and try again",
"account-deleted": "Your account has been successfully deleted",
"progress-reset": "Your progress has been reset",
@@ -39,7 +39,7 @@ export enum FlashMessages {
None = '',
NotEligible = 'flash.not-eligible',
NotHonest = 'flash.not-honest',
NotRight = 'flash.not-right',
GenericError = 'flash.generic-error',
ProfilePrivate = 'flash.profile-private',
ProgressReset = 'flash.progress-reset',
ProvideUsername = 'flash.provide-username',
+1 -1
View File
@@ -12,7 +12,7 @@ export const reallyWeirdErrorMessage = {
export const reportedErrorMessage = {
type: 'danger',
message: FlashMessages.NotRight
message: FlashMessages.GenericError
};
export const certificateMissingErrorMessage = {
+1 -1
View File
@@ -54,7 +54,7 @@ const toneUrls = {
// [FlashMessages.None]: '',
[FlashMessages.NotEligible]: TRY_AGAIN,
[FlashMessages.NotHonest]: TRY_AGAIN,
[FlashMessages.NotRight]: TRY_AGAIN,
[FlashMessages.GenericError]: TRY_AGAIN,
[FlashMessages.ProfilePrivate]: TRY_AGAIN,
[FlashMessages.ProgressReset]: TRY_AGAIN,
[FlashMessages.ProvideUsername]: TRY_AGAIN,