@@ -82,7 +82,7 @@ export const serveExampleRpc = async <Context>(service: ExampleServer<Context>,
8282 if ( ! urlPath . startsWith ( '/rpc/' ) ) return null
8383 const parts = urlPath . split ( '/' ) . filter ( Boolean )
8484 if ( parts . length !== 3 || parts [ 0 ] !== 'rpc' || parts [ 1 ] !== 'Example' ) return null
85- const method = parts [ 2 ]
85+ const method = parts [ 2 ] !
8686 try {
8787 const result = await dispatchExampleRequest ( service , ctx , method , body )
8888 return {
@@ -235,19 +235,16 @@ const validateType = (value: any, type: string) => {
235235type WebrpcErrorParams = { name ?: string , code ?: number , message ?: string , status ?: number , cause ?: string }
236236
237237export class WebrpcError extends Error {
238- name : string
239238 code : number
240- message : string
241239 status : number
242- cause ?: string
243240
244241 constructor ( error : WebrpcErrorParams = { } ) {
245242 super ( error . message )
246243 this . name = error . name || 'WebrpcEndpointError'
247244 this . code = typeof error . code === 'number' ? error . code : 0
248245 this . message = error . message || `endpoint error`
249246 this . status = typeof error . status === 'number' ? error . status : 400
250- this . cause = error . cause
247+ if ( error . cause !== undefined ) this . cause = error . cause
251248 Object . setPrototypeOf ( this , WebrpcError . prototype )
252249 }
253250
@@ -264,7 +261,7 @@ export class WebrpcEndpointError extends WebrpcError {
264261 this . code = typeof error . code === 'number' ? error . code : 0
265262 this . message = error . message || `endpoint error`
266263 this . status = typeof error . status === 'number' ? error . status : 400
267- this . cause = error . cause
264+ if ( error . cause !== undefined ) this . cause = error . cause
268265 Object . setPrototypeOf ( this , WebrpcEndpointError . prototype )
269266 }
270267}
@@ -276,7 +273,7 @@ export class WebrpcRequestFailedError extends WebrpcError {
276273 this . code = typeof error . code === 'number' ? error . code : - 1
277274 this . message = error . message || `request failed`
278275 this . status = typeof error . status === 'number' ? error . status : 400
279- this . cause = error . cause
276+ if ( error . cause !== undefined ) this . cause = error . cause
280277 Object . setPrototypeOf ( this , WebrpcRequestFailedError . prototype )
281278 }
282279}
@@ -288,7 +285,7 @@ export class WebrpcBadRouteError extends WebrpcError {
288285 this . code = typeof error . code === 'number' ? error . code : - 2
289286 this . message = error . message || `bad route`
290287 this . status = typeof error . status === 'number' ? error . status : 404
291- this . cause = error . cause
288+ if ( error . cause !== undefined ) this . cause = error . cause
292289 Object . setPrototypeOf ( this , WebrpcBadRouteError . prototype )
293290 }
294291}
@@ -300,7 +297,7 @@ export class WebrpcBadMethodError extends WebrpcError {
300297 this . code = typeof error . code === 'number' ? error . code : - 3
301298 this . message = error . message || `bad method`
302299 this . status = typeof error . status === 'number' ? error . status : 405
303- this . cause = error . cause
300+ if ( error . cause !== undefined ) this . cause = error . cause
304301 Object . setPrototypeOf ( this , WebrpcBadMethodError . prototype )
305302 }
306303}
@@ -312,7 +309,7 @@ export class WebrpcBadRequestError extends WebrpcError {
312309 this . code = typeof error . code === 'number' ? error . code : - 4
313310 this . message = error . message || `bad request`
314311 this . status = typeof error . status === 'number' ? error . status : 400
315- this . cause = error . cause
312+ if ( error . cause !== undefined ) this . cause = error . cause
316313 Object . setPrototypeOf ( this , WebrpcBadRequestError . prototype )
317314 }
318315}
@@ -324,7 +321,7 @@ export class WebrpcBadResponseError extends WebrpcError {
324321 this . code = typeof error . code === 'number' ? error . code : - 5
325322 this . message = error . message || `bad response`
326323 this . status = typeof error . status === 'number' ? error . status : 500
327- this . cause = error . cause
324+ if ( error . cause !== undefined ) this . cause = error . cause
328325 Object . setPrototypeOf ( this , WebrpcBadResponseError . prototype )
329326 }
330327}
@@ -336,7 +333,7 @@ export class WebrpcServerPanicError extends WebrpcError {
336333 this . code = typeof error . code === 'number' ? error . code : - 6
337334 this . message = error . message || `server panic`
338335 this . status = typeof error . status === 'number' ? error . status : 500
339- this . cause = error . cause
336+ if ( error . cause !== undefined ) this . cause = error . cause
340337 Object . setPrototypeOf ( this , WebrpcServerPanicError . prototype )
341338 }
342339}
@@ -348,7 +345,7 @@ export class WebrpcInternalErrorError extends WebrpcError {
348345 this . code = typeof error . code === 'number' ? error . code : - 7
349346 this . message = error . message || `internal error`
350347 this . status = typeof error . status === 'number' ? error . status : 500
351- this . cause = error . cause
348+ if ( error . cause !== undefined ) this . cause = error . cause
352349 Object . setPrototypeOf ( this , WebrpcInternalErrorError . prototype )
353350 }
354351}
@@ -360,7 +357,7 @@ export class WebrpcClientAbortedError extends WebrpcError {
360357 this . code = typeof error . code === 'number' ? error . code : - 8
361358 this . message = error . message || `request aborted by client`
362359 this . status = typeof error . status === 'number' ? error . status : 400
363- this . cause = error . cause
360+ if ( error . cause !== undefined ) this . cause = error . cause
364361 Object . setPrototypeOf ( this , WebrpcClientAbortedError . prototype )
365362 }
366363}
@@ -372,7 +369,7 @@ export class WebrpcStreamLostError extends WebrpcError {
372369 this . code = typeof error . code === 'number' ? error . code : - 9
373370 this . message = error . message || `stream lost`
374371 this . status = typeof error . status === 'number' ? error . status : 400
375- this . cause = error . cause
372+ if ( error . cause !== undefined ) this . cause = error . cause
376373 Object . setPrototypeOf ( this , WebrpcStreamLostError . prototype )
377374 }
378375}
@@ -384,7 +381,7 @@ export class WebrpcStreamFinishedError extends WebrpcError {
384381 this . code = typeof error . code === 'number' ? error . code : - 10
385382 this . message = error . message || `stream finished`
386383 this . status = typeof error . status === 'number' ? error . status : 200
387- this . cause = error . cause
384+ if ( error . cause !== undefined ) this . cause = error . cause
388385 Object . setPrototypeOf ( this , WebrpcStreamFinishedError . prototype )
389386 }
390387}
@@ -401,7 +398,7 @@ export class UnauthorizedError extends WebrpcError {
401398 this . code = typeof error . code === 'number' ? error . code : 1000
402399 this . message = error . message || `Unauthorized access`
403400 this . status = typeof error . status === 'number' ? error . status : 401
404- this . cause = error . cause
401+ if ( error . cause !== undefined ) this . cause = error . cause
405402 Object . setPrototypeOf ( this , UnauthorizedError . prototype )
406403 }
407404}
@@ -413,7 +410,7 @@ export class PermissionDeniedError extends WebrpcError {
413410 this . code = typeof error . code === 'number' ? error . code : 1001
414411 this . message = error . message || `Permission denied`
415412 this . status = typeof error . status === 'number' ? error . status : 403
416- this . cause = error . cause
413+ if ( error . cause !== undefined ) this . cause = error . cause
417414 Object . setPrototypeOf ( this , PermissionDeniedError . prototype )
418415 }
419416}
@@ -425,7 +422,7 @@ export class SessionExpiredError extends WebrpcError {
425422 this . code = typeof error . code === 'number' ? error . code : 1002
426423 this . message = error . message || `Session expired`
427424 this . status = typeof error . status === 'number' ? error . status : 403
428- this . cause = error . cause
425+ if ( error . cause !== undefined ) this . cause = error . cause
429426 Object . setPrototypeOf ( this , SessionExpiredError . prototype )
430427 }
431428}
@@ -437,7 +434,7 @@ export class GeoblockedError extends WebrpcError {
437434 this . code = typeof error . code === 'number' ? error . code : 1003
438435 this . message = error . message || `Geoblocked region`
439436 this . status = typeof error . status === 'number' ? error . status : 451
440- this . cause = error . cause
437+ if ( error . cause !== undefined ) this . cause = error . cause
441438 Object . setPrototypeOf ( this , GeoblockedError . prototype )
442439 }
443440}
@@ -449,7 +446,7 @@ export class RateLimitedError extends WebrpcError {
449446 this . code = typeof error . code === 'number' ? error . code : 1004
450447 this . message = error . message || `Rate-limited. Please slow down.`
451448 this . status = typeof error . status === 'number' ? error . status : 429
452- this . cause = error . cause
449+ if ( error . cause !== undefined ) this . cause = error . cause
453450 Object . setPrototypeOf ( this , RateLimitedError . prototype )
454451 }
455452}
@@ -461,7 +458,7 @@ export class CorsDisallowedError extends WebrpcError {
461458 this . code = typeof error . code === 'number' ? error . code : 1005
462459 this . message = error . message || `CORS disallowed. JWT can't be used from a web app.`
463460 this . status = typeof error . status === 'number' ? error . status : 403
464- this . cause = error . cause
461+ if ( error . cause !== undefined ) this . cause = error . cause
465462 Object . setPrototypeOf ( this , CorsDisallowedError . prototype )
466463 }
467464}
0 commit comments