Skip to content

Commit

Permalink
chore: only log warning if media type is not supported (415) (#6847)
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig authored Jun 3, 2024
1 parent 2b4c166 commit 519b05e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/beacon-node/src/api/rest/base.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 519b05e

Please sign in to comment.