Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"@automa/bot": "~0.3.0",
"@fastify/autoload": "~6.3.1",
"@fastify/error": "~4.2.0",
"@fastify/helmet": "~13.0.2",
"@fastify/sensible": "~6.0.3",
"@fastify/swagger": "~9.5.2",
Expand All @@ -19,7 +20,7 @@
"@opentelemetry/semantic-conventions": "~1.26.0",
"@segment/analytics-node": "~1.1.0",
"@sentry/node": "~7.59.3",
"fastify": "~5.6.1",
"fastify": "~5.6.2",
"fastify-plugin": "~5.1.0",
"http-errors": "~2.0.0",
"nested-env-schema": "~1.3.1",
Expand Down
54 changes: 29 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { env, isProduction, isTest, version } from './env';

import fastify from 'fastify';
import fastifyAutoload from '@fastify/autoload';
import { FastifyError } from '@fastify/error';
import fastifyHelmet from '@fastify/helmet';
import fastifySensible from '@fastify/sensible';
import fastifySwagger from '@fastify/swagger';
Expand Down Expand Up @@ -37,14 +38,16 @@ export const server = async () => {
return error;
}

if (error.code === 'FST_ERR_VALIDATION') {
return reply.unprocessableEntity(error.message);
} else if (error.code === 'FST_ERR_CTP_BODY_TOO_LARGE') {
return reply.payloadTooLarge(error.message);
} else if (error.code === 'FST_ERR_CTP_INVALID_MEDIA_TYPE') {
return reply.unsupportedMediaType(error.message);
} else if (error.statusCode === 400) {
return reply.badRequest(error.message);
if (error instanceof FastifyError) {
if (error.code === 'FST_ERR_VALIDATION') {
return reply.unprocessableEntity(error.message);
} else if (error.code === 'FST_ERR_CTP_BODY_TOO_LARGE') {
return reply.payloadTooLarge(error.message);
} else if (error.code === 'FST_ERR_CTP_INVALID_MEDIA_TYPE') {
return reply.unsupportedMediaType(error.message);
} else if (error.statusCode === 400) {
return reply.badRequest(error.message);
}
}

app.error.capture(error, { method: request.method, url: request.url });
Expand Down
Loading