From 953a5d743da4af33fd573c7853dde9883e1b1a34 Mon Sep 17 00:00:00 2001 From: Roman Kalyakin Date: Mon, 24 Feb 2025 10:16:49 +0100 Subject: [PATCH] better handle filter deserialization --- src/app.hooks.ts | 9 +++++++-- src/services/images/images-v1.hooks.ts | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app.hooks.ts b/src/app.hooks.ts index 46c680c9..d07770c1 100644 --- a/src/app.hooks.ts +++ b/src/app.hooks.ts @@ -44,13 +44,18 @@ const requireAuthentication = return context } -const LoggingExcludedStatusCodes = [400, 401, 403, 404, 422] +const LoggingExcludedStatusCodesInternalApi = [401, 403, 404] +const LoggingExcludedStatusCodesPublicApi = [400, 401, 403, 404, 422] const errorHandler = (ctx: HookContext) => { + const excludedStatusCodes = ctx.app.get('isPublicApi') + ? LoggingExcludedStatusCodesPublicApi + : LoggingExcludedStatusCodesInternalApi + if (ctx.error) { const error = ctx.error - if (!LoggingExcludedStatusCodes.includes(error.code) || !error.code) { + if (!excludedStatusCodes.includes(error.code) || !error.code) { console.error( `ERROR ${error.code || error.type || 'N/A'} ${error.name} at ${ctx.path}:${ctx.method}: `, error.stack diff --git a/src/services/images/images-v1.hooks.ts b/src/services/images/images-v1.hooks.ts index d9bc037c..e08d5a26 100644 --- a/src/services/images/images-v1.hooks.ts +++ b/src/services/images/images-v1.hooks.ts @@ -112,8 +112,9 @@ const convertItemToNewImageFormat = (context: HookContext) context.result = newResult } -const deserializeFilters = (serializedFilters: string) => { +const deserializeFilters = (serializedFilters: string | object) => { if (serializedFilters == null) return [] + if (typeof serializedFilters !== 'string') return serializedFilters try { return protobuf.searchQuery.deserialize(serializedFilters).filters || [] } catch (error) {