File tree Expand file tree Collapse file tree
plugins/plugin-hono-server/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -183,6 +183,27 @@ export class ObjectStackProtocolImplementation implements IObjectStackProtocol {
183183
184184 async batchData ( object : string , request : BatchUpdateRequest ) : Promise < BatchUpdateResponse > {
185185 const startTime = Date . now ( ) ;
186+
187+ // Validate request
188+ if ( ! request || ! request . records ) {
189+ return {
190+ success : false ,
191+ operation : request ?. operation ,
192+ total : 0 ,
193+ succeeded : 0 ,
194+ failed : 0 ,
195+ results : [ ] ,
196+ error : {
197+ code : 'validation_error' ,
198+ message : 'Invalid request: records array is required' ,
199+ } ,
200+ meta : {
201+ timestamp : new Date ( ) . toISOString ( ) ,
202+ duration : Date . now ( ) - startTime ,
203+ } ,
204+ } ;
205+ }
206+
186207 const { operation, records, options } = request ;
187208 const atomic = options ?. atomic ?? true ;
188209 const returnRecords = options ?. returnRecords ?? false ;
@@ -339,6 +360,11 @@ export class ObjectStackProtocolImplementation implements IObjectStackProtocol {
339360 }
340361
341362 async createManyData ( object : string , records : any [ ] ) : Promise < any [ ] > {
363+ // Validate input
364+ if ( ! records || ! Array . isArray ( records ) ) {
365+ throw new Error ( 'Invalid input: records must be an array' ) ;
366+ }
367+
342368 const results : any [ ] = [ ] ;
343369
344370 for ( const record of records ) {
Original file line number Diff line number Diff line change @@ -27,19 +27,33 @@ export class HonoHttpServer implements IHttpServer {
2727 // internal helper to convert standard handler to Hono handler
2828 private wrap ( handler : RouteHandler ) {
2929 return async ( c : any ) => {
30+ let body : any = { } ;
31+
32+ // Try to parse JSON body first if content-type is JSON
33+ if ( c . req . header ( 'content-type' ) ?. includes ( 'application/json' ) ) {
34+ try {
35+ body = await c . req . json ( ) ;
36+ } catch ( e ) {
37+ // If JSON parsing fails, try parseBody
38+ try {
39+ body = await c . req . parseBody ( ) ;
40+ } catch ( e2 ) { }
41+ }
42+ } else {
43+ // For non-JSON content types, use parseBody
44+ try {
45+ body = await c . req . parseBody ( ) ;
46+ } catch ( e ) { }
47+ }
48+
3049 const req = {
3150 params : c . req . param ( ) ,
3251 query : c . req . query ( ) ,
33- body : await c . req . parseBody ( ) . catch ( ( ) => { } ) , // fallback
52+ body,
3453 headers : c . req . header ( ) ,
3554 method : c . req . method ,
3655 path : c . req . path
3756 } ;
38-
39- // Try to parse JSON body if possible
40- if ( c . req . header ( 'content-type' ) ?. includes ( 'application/json' ) ) {
41- try { req . body = await c . req . json ( ) ; } catch ( e ) { }
42- }
4357
4458 let capturedResponse : any ;
4559
Original file line number Diff line number Diff line change @@ -158,7 +158,13 @@ export class HonoServerPlugin implements Plugin {
158158
159159 // Batch Operations
160160 this . server . post ( '/api/v1/data/:object/batch' , async ( req , res ) => {
161- ctx . logger . debug ( 'Batch operation request' , { object : req . params . object , operation : req . body ?. operation } ) ;
161+ ctx . logger . info ( 'Batch operation request' , {
162+ object : req . params . object ,
163+ operation : req . body ?. operation ,
164+ hasBody : ! ! req . body ,
165+ bodyType : typeof req . body ,
166+ bodyKeys : req . body ? Object . keys ( req . body ) : [ ]
167+ } ) ;
162168 try {
163169 const result = await p . batchData ( req . params . object , req . body ) ;
164170 ctx . logger . info ( 'Batch operation completed' , {
You can’t perform that action at this time.
0 commit comments