File tree Expand file tree Collapse file tree 4 files changed +29
-17
lines changed
rivetkit-typescript/packages/rivetkit/src
schemas/client-protocol-zod Expand file tree Collapse file tree 4 files changed +29
-17
lines changed Original file line number Diff line number Diff line change @@ -299,20 +299,29 @@ export async function processMessage<
299299 errorData ,
300300 TO_CLIENT_VERSIONED ,
301301 ToClientSchema ,
302- // JSON: metadata is the raw value
303- ( value ) : ToClientJson => ( {
304- body : {
305- tag : "Error" as const ,
306- val : {
307- group : value . group ,
308- code : value . code ,
309- message : value . message ,
310- metadata : value . metadata ?? null ,
311- actionId : value . actionId ?? null ,
302+ // JSON: metadata is the raw value (keep as undefined if not present)
303+ ( value ) : ToClientJson => {
304+ const val : any = {
305+ group : value . group ,
306+ code : value . code ,
307+ message : value . message ,
308+ actionId :
309+ value . actionId !== undefined
310+ ? value . actionId
311+ : null ,
312+ } ;
313+ if ( value . metadata !== undefined ) {
314+ val . metadata = value . metadata ;
315+ }
316+ return {
317+ body : {
318+ tag : "Error" as const ,
319+ val,
312320 } ,
313- } ,
314- } ) ,
321+ } ;
322+ } ,
315323 // BARE/CBOR: metadata needs to be CBOR-encoded to ArrayBuffer
324+ // Note: protocol.Error expects `| null` for optional fields (BARE protocol)
316325 ( value ) : protocol . ToClient => ( {
317326 body : {
318327 tag : "Error" as const ,
@@ -325,7 +334,10 @@ export async function processMessage<
325334 cbor . encode ( value . metadata ) ,
326335 )
327336 : null ,
328- actionId : value . actionId ?? null ,
337+ actionId :
338+ value . actionId !== undefined
339+ ? value . actionId
340+ : null ,
329341 } ,
330342 } ,
331343 } ) ,
Original file line number Diff line number Diff line change @@ -157,7 +157,7 @@ export async function sendHttpRequest<
157157 message : bare . message ,
158158 metadata : bare . metadata
159159 ? cbor . decode ( new Uint8Array ( bare . metadata ) )
160- : null ,
160+ : undefined ,
161161 } ) ,
162162 ) ;
163163 } catch ( error ) {
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ export function handleRouteError(error: unknown, c: HonoContext) {
8282 group : value . group ,
8383 code : value . code ,
8484 message : value . message ,
85- metadata : value . metadata ?? null ,
85+ metadata : value . metadata ,
8686 } ) ,
8787 // BARE/CBOR: metadata needs to be CBOR-encoded to ArrayBuffer
8888 ( value ) : protocol . HttpResponseError => ( {
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ export const ErrorSchema = z.object({
1515 group : z . string ( ) ,
1616 code : z . string ( ) ,
1717 message : z . string ( ) ,
18- metadata : z . unknown ( ) . nullable ( ) ,
18+ metadata : z . unknown ( ) . optional ( ) ,
1919 actionId : OptionalUintSchema ,
2020} ) ;
2121export type Error = z . infer < typeof ErrorSchema > ;
@@ -89,7 +89,7 @@ export const HttpResponseErrorSchema = z.object({
8989 group : z . string ( ) ,
9090 code : z . string ( ) ,
9191 message : z . string ( ) ,
92- metadata : z . unknown ( ) . nullable ( ) ,
92+ metadata : z . unknown ( ) . optional ( ) ,
9393} ) ;
9494export type HttpResponseError = z . infer < typeof HttpResponseErrorSchema > ;
9595
You can’t perform that action at this time.
0 commit comments