mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-22 13:00:56 -04:00
chore(api): add logging for 404 not found requests (#59068)
Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
This commit is contained in:
@@ -14,17 +14,20 @@ import { getRedirectParams } from '../utils/redirection';
|
||||
const fourOhFour: FastifyPluginCallback = (fastify, _options, done) => {
|
||||
// If the request accepts JSON and does not specifically prefer text/html,
|
||||
// this will return a 404 JSON response. Everything else will be redirected.
|
||||
fastify.setNotFoundHandler((request, reply) => {
|
||||
const accepted = request.accepts().type(['json', 'html']);
|
||||
fastify.setNotFoundHandler((req, reply) => {
|
||||
const logger = fastify.log.child({ req });
|
||||
const accepted = req.accepts().type(['json', 'html']);
|
||||
|
||||
logger.debug('User requested path that does not exist');
|
||||
|
||||
if (accepted == 'json') {
|
||||
void reply.code(404).send({ error: 'path not found' });
|
||||
} else {
|
||||
const { origin } = getRedirectParams(request);
|
||||
const { origin } = getRedirectParams(req);
|
||||
void reply.status(302);
|
||||
void reply.redirectWithMessage(`${origin}/404`, {
|
||||
type: 'danger',
|
||||
content: `We couldn't find path ${request.url}`
|
||||
content: `We couldn't find path ${req.url}`
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user