Skip to content

Commit d80b800

Browse files
authored
better handle filter deserialization (#521)
1 parent 4094cf3 commit d80b800

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/app.hooks.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,18 @@ const requireAuthentication =
4444
return context
4545
}
4646

47-
const LoggingExcludedStatusCodes = [400, 401, 403, 404, 422]
47+
const LoggingExcludedStatusCodesInternalApi = [401, 403, 404]
48+
const LoggingExcludedStatusCodesPublicApi = [400, 401, 403, 404, 422]
4849

4950
const errorHandler = (ctx: HookContext<ImpressoApplication>) => {
51+
const excludedStatusCodes = ctx.app.get('isPublicApi')
52+
? LoggingExcludedStatusCodesPublicApi
53+
: LoggingExcludedStatusCodesInternalApi
54+
5055
if (ctx.error) {
5156
const error = ctx.error
5257

53-
if (!LoggingExcludedStatusCodes.includes(error.code) || !error.code) {
58+
if (!excludedStatusCodes.includes(error.code) || !error.code) {
5459
console.error(
5560
`ERROR ${error.code || error.type || 'N/A'} ${error.name} at ${ctx.path}:${ctx.method}: `,
5661
error.stack

src/services/images/images-v1.hooks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ const convertItemToNewImageFormat = (context: HookContext<ImpressoApplication>)
112112
context.result = newResult
113113
}
114114

115-
const deserializeFilters = (serializedFilters: string) => {
115+
const deserializeFilters = (serializedFilters: string | object) => {
116116
if (serializedFilters == null) return []
117+
if (typeof serializedFilters !== 'string') return serializedFilters
117118
try {
118119
return protobuf.searchQuery.deserialize(serializedFilters).filters || []
119120
} catch (error) {

0 commit comments

Comments
 (0)