From 519b05ef19984fdd158ddc9c7921db7dfff4a93e Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Tue, 4 Jun 2024 00:12:17 +0200 Subject: [PATCH] chore: only log warning if media type is not supported (415) (#6847) --- packages/beacon-node/src/api/rest/base.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/beacon-node/src/api/rest/base.ts b/packages/beacon-node/src/api/rest/base.ts index b32e0079db53..86eab0ba46d4 100644 --- a/packages/beacon-node/src/api/rest/base.ts +++ b/packages/beacon-node/src/api/rest/base.ts @@ -1,5 +1,5 @@ import {parse as parseQueryString} from "qs"; -import {FastifyInstance, FastifyRequest, fastify} from "fastify"; +import {FastifyInstance, FastifyRequest, fastify, errorCodes} from "fastify"; import {fastifyCors} from "@fastify/cors"; import bearerAuthPlugin from "@fastify/bearer-auth"; import {ErrorAborted, Gauge, Histogram, Logger} from "@lodestar/utils"; @@ -28,6 +28,11 @@ export type RestApiServerMetrics = SocketMetrics & { errors: Gauge<{operationId: string}>; }; +/** + * Error code used by Fastify if media type is not supported (415) + */ +const INVALID_MEDIA_TYPE_CODE = errorCodes.FST_ERR_CTP_INVALID_MEDIA_TYPE().code; + /** * REST API powered by `fastify` server. */ @@ -107,7 +112,7 @@ export class RestApiServer { const operationId = getOperationId(req); - if (err instanceof ApiError) { + if (err instanceof ApiError || err.code === INVALID_MEDIA_TYPE_CODE) { this.logger.warn(`Req ${req.id} ${operationId} failed`, {reason: err.message}); } else { this.logger.error(`Req ${req.id} ${operationId} error`, {}, err);