File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change 1- import type { Handle , RequestEvent } from '@sveltejs/kit' ;
1+ import { type Handle , type RequestEvent } from '@sveltejs/kit' ;
22import type { ClientContract } from '@zenstackhq/orm' ;
33import type { SchemaDef } from '@zenstackhq/orm/schema' ;
44import { logInternalError , type CommonAdapterOptions } from '../common' ;
@@ -37,9 +37,18 @@ export default function createHandler<Schema extends SchemaDef>(options: SvelteK
3737 const query = Object . fromEntries ( event . url . searchParams ) ;
3838 let requestBody : unknown ;
3939 if ( event . request . body ) {
40- const text = await event . request . text ( ) ;
41- if ( text ) {
42- requestBody = JSON . parse ( text ) ;
40+ try {
41+ const text = await event . request . text ( ) ;
42+ if ( text ) {
43+ requestBody = JSON . parse ( text ) ;
44+ }
45+ } catch {
46+ return new Response ( JSON . stringify ( { message : 'invalid JSON payload' } ) , {
47+ status : 400 ,
48+ headers : {
49+ 'content-type' : 'application/json' ,
50+ } ,
51+ } ) ;
4352 }
4453 }
4554
Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ describe('Fastify adapter tests - rest handler', () => {
146146 app . register ( ZenStackFastifyPlugin , {
147147 prefix : '/api' ,
148148 getClient : ( ) => client ,
149- apiHandler : new RestApiHandler ( { schema : client . schema , endpoint : 'http://localhost/api' } ) ,
149+ apiHandler : new RestApiHandler ( { schema : client . $ schema, endpoint : 'http://localhost/api' } ) ,
150150 } ) ;
151151
152152 let r = await app . inject ( {
You can’t perform that action at this time.
0 commit comments