From 7469f0decbe18d6f80e41344cde73d940ab5517a Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 21 Apr 2023 15:44:59 +0200 Subject: [PATCH] Use fastify `req.routeConfig` instead of `res.context.config` (#5398) --- packages/beacon-node/src/api/rest/base.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/beacon-node/src/api/rest/base.ts b/packages/beacon-node/src/api/rest/base.ts index 045be3836323..b65e52fd8b01 100644 --- a/packages/beacon-node/src/api/rest/base.ts +++ b/packages/beacon-node/src/api/rest/base.ts @@ -78,25 +78,25 @@ export class RestApiServer { // Log all incoming request to debug (before parsing). TODO: Should we hook latter in the lifecycle? https://www.fastify.io/docs/latest/Lifecycle/ // Note: Must be an async method so fastify can continue the release lifecycle. Otherwise we must call done() or the request stalls - server.addHook("onRequest", async (req, res) => { - const {operationId} = res.context.config as RouteConfig; + server.addHook("onRequest", async (req, _res) => { + const {operationId} = req.routeConfig as RouteConfig; this.logger.debug(`Req ${req.id} ${req.ip} ${operationId}`); metrics?.requests.inc({operationId}); }); // Log after response server.addHook("onResponse", async (req, res) => { - const {operationId} = res.context.config as RouteConfig; + const {operationId} = req.routeConfig as RouteConfig; this.logger.debug(`Res ${req.id} ${operationId} - ${res.raw.statusCode}`); metrics?.responseTime.observe({operationId}, res.getResponseTime() / 1000); }); - server.addHook("onError", async (req, res, err) => { + server.addHook("onError", async (req, _res, err) => { // Don't log ErrorAborted errors, they happen on node shutdown and are not useful // Don't log NodeISSyncing errors, they happen very frequently while syncing and the validator polls duties if (err instanceof ErrorAborted || err instanceof NodeIsSyncing) return; - const {operationId} = res.context.config as RouteConfig; + const {operationId} = req.routeConfig as RouteConfig; if (err instanceof ApiError) { this.logger.warn(`Req ${req.id} ${operationId} failed`, {reason: err.message});