mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
chore(api): improve log statements (#59992)
This commit is contained in:
committed by
GitHub
parent
464181b3b8
commit
a905083bf8
@@ -170,7 +170,10 @@ describe('errorHandling', () => {
|
||||
url: '/test'
|
||||
});
|
||||
|
||||
expect(logSpy).toHaveBeenCalledWith(Error('a very bad thing happened'));
|
||||
expect(logSpy).toHaveBeenCalledWith(
|
||||
Error('a very bad thing happened'),
|
||||
'Error in request'
|
||||
);
|
||||
});
|
||||
|
||||
it('should call fastify.log.warn when a bad request error occurs', async () => {
|
||||
@@ -181,7 +184,10 @@ describe('errorHandling', () => {
|
||||
url: '/test-bad-request'
|
||||
});
|
||||
|
||||
expect(logSpy).toHaveBeenCalledWith(Error('a very bad thing happened'));
|
||||
expect(logSpy).toHaveBeenCalledWith(
|
||||
Error('a very bad thing happened'),
|
||||
'CSRF error in request'
|
||||
);
|
||||
});
|
||||
|
||||
it('should NOT log when a CSRF error is thrown', async () => {
|
||||
|
||||
@@ -39,9 +39,9 @@ const errorHandling: FastifyPluginCallback = (fastify, _options, done) => {
|
||||
|
||||
if (!isCSRFError) {
|
||||
if (reply.statusCode >= 500) {
|
||||
logger.error(error);
|
||||
logger.error(error, 'Error in request');
|
||||
} else {
|
||||
logger.warn(error);
|
||||
logger.warn(error, 'CSRF error in request');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ export const challengeRoutes: FastifyPluginCallbackTypebox = (
|
||||
}
|
||||
} catch (error) {
|
||||
// TODO(Post-MVP): don't catch, just let Sentry handle this.
|
||||
logger.error(error);
|
||||
logger.error(error, 'Error submitting coderoad challenge');
|
||||
fastify.Sentry.captureException(error);
|
||||
void reply.code(400);
|
||||
return {
|
||||
@@ -669,7 +669,7 @@ export const challengeRoutes: FastifyPluginCallbackTypebox = (
|
||||
completedDate
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
logger.error(error, 'Error submitting Microsoft trophy challenge');
|
||||
fastify.Sentry.captureException(error);
|
||||
void reply.code(500);
|
||||
return {
|
||||
@@ -884,7 +884,7 @@ export const challengeRoutes: FastifyPluginCallbackTypebox = (
|
||||
examResults
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
logger.error(error, 'Error submitting exam challenge');
|
||||
fastify.Sentry.captureException(error);
|
||||
void reply.code(500);
|
||||
return {
|
||||
|
||||
@@ -90,8 +90,7 @@ export const donateRoutes: FastifyPluginCallbackTypebox = (
|
||||
isDonating: true
|
||||
} as const;
|
||||
} catch (error) {
|
||||
logger.error(`User ${req.user?.id} failed to donate`);
|
||||
logger.error(error);
|
||||
logger.error(error, `User ${req.user?.id} failed to donate`);
|
||||
fastify.Sentry.captureException(error);
|
||||
void reply.code(500);
|
||||
return {
|
||||
@@ -227,8 +226,7 @@ export const donateRoutes: FastifyPluginCallbackTypebox = (
|
||||
isDonating: true
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(`User ${req.user?.id} failed to donate`);
|
||||
logger.error(error);
|
||||
logger.error(error, `User ${req.user?.id} failed to donate`);
|
||||
fastify.Sentry.captureException(error);
|
||||
void reply.code(500);
|
||||
return reply.send({
|
||||
|
||||
Reference in New Issue
Block a user