Skip to content

Commit

Permalink
fix(zenstackhq#300): handle invalid json in openapi query params grac…
Browse files Browse the repository at this point in the history
…efully (zenstackhq#303)
  • Loading branch information
ymc9 authored Mar 29, 2023
2 parents 1008b0e + 68a08a3 commit 8bdc827
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/server/src/openapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ export async function handleRequest({
if (method !== 'GET') {
return { status: 400, body: { message: 'invalid request method, only GET is supported' } };
}
args = query?.q ? unmarshal(query.q as string) : {};
try {
args = query?.q ? unmarshal(query.q as string) : {};
} catch {
return { status: 400, body: { message: 'query param must contain valid JSON' } };
}
break;

case 'update':
Expand All @@ -158,7 +162,11 @@ export async function handleRequest({
if (method !== 'DELETE') {
return { status: 400, body: { message: 'invalid request method, only DELETE is supported' } };
}
args = query?.q ? unmarshal(query.q as string) : {};
try {
args = query?.q ? unmarshal(query.q as string) : {};
} catch {
return { status: 400, body: { message: 'query param must contain valid JSON' } };
}
break;

default:
Expand Down

0 comments on commit 8bdc827

Please sign in to comment.