Skip to content

Commit

Permalink
better handle filter deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
theorm committed Feb 24, 2025
1 parent 4094cf3 commit 953a5d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/app.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImpressoApplication>) => {
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
Expand Down
3 changes: 2 additions & 1 deletion src/services/images/images-v1.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ const convertItemToNewImageFormat = (context: HookContext<ImpressoApplication>)
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) {
Expand Down

0 comments on commit 953a5d7

Please sign in to comment.