@atproto/lex-client 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/xrpc.test.ts CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  XrpcInternalError,
10
10
  XrpcInvalidResponseError,
11
11
  XrpcResponseError,
12
- XrpcUpstreamError,
12
+ XrpcResponseValidationError,
13
13
  } from './errors.js'
14
14
  import { XrpcResponse } from './response.js'
15
15
  import { xrpc, xrpcSafe } from './xrpc.js'
@@ -74,7 +74,6 @@ const testQueryGetBlobRef = l.query(
74
74
  l.params(),
75
75
  l.jsonPayload({
76
76
  blobRef: l.blob({
77
- allowLegacy: false,
78
77
  accept: ['image/png'],
79
78
  maxSize: 10,
80
79
  }),
@@ -221,6 +220,17 @@ describe(xrpc, () => {
221
220
  expect(response.success).toBe(true)
222
221
  expect(response.body).toEqual({ value: 'ok' })
223
222
  })
223
+
224
+ it('ignores output for no-output queries', async () => {
225
+ const fetchHandler = vi.fn<FetchHandler>(async () => {
226
+ return Response.json({ unexpected: 'data' })
227
+ })
228
+
229
+ const response = await xrpc(fetchHandler, testNoOutputQuery)
230
+
231
+ expect(response.success).toBe(true)
232
+ expect(response.body).toStrictEqual({ unexpected: 'data' })
233
+ })
224
234
  })
225
235
 
226
236
  describe('error handling', () => {
@@ -271,7 +281,7 @@ describe(xrpc, () => {
271
281
  ).rejects.toSatisfy((err) => {
272
282
  assert(err instanceof XrpcResponseError)
273
283
  expect(err.status).toBe(400)
274
- expect(err.body).toEqual({
284
+ expect(err.toJSON()).toEqual({
275
285
  error: 'TestError',
276
286
  message: 'bad request',
277
287
  })
@@ -297,7 +307,7 @@ describe(xrpc, () => {
297
307
  })
298
308
  })
299
309
 
300
- it('throws XrpcUpstreamError for non-XRPC error response', async () => {
310
+ it('throws XrpcResponseError for non-XRPC error response', async () => {
301
311
  const fetchHandler = vi.fn<FetchHandler>(async () => {
302
312
  return new Response('Not Found', {
303
313
  status: 404,
@@ -308,13 +318,13 @@ describe(xrpc, () => {
308
318
  await expect(
309
319
  xrpc(fetchHandler, testQuery, { params: { limit: 10 } }),
310
320
  ).rejects.toSatisfy((err) => {
311
- assert(err instanceof XrpcUpstreamError)
312
- expect(err.message).toBe('Invalid response payload')
321
+ assert(err instanceof XrpcResponseError)
322
+ expect(err.message).toBe('Upstream server responded with a 404 error')
313
323
  return true
314
324
  })
315
325
  })
316
326
 
317
- it('throws XrpcUpstreamError for 500 without valid error payload', async () => {
327
+ it('throws XrpcResponseError for 500 without valid error payload', async () => {
318
328
  const fetchHandler = vi.fn<FetchHandler>(async () => {
319
329
  return new Response('Internal Server Error', {
320
330
  status: 500,
@@ -325,8 +335,8 @@ describe(xrpc, () => {
325
335
  await expect(
326
336
  xrpc(fetchHandler, testQuery, { params: { limit: 10 } }),
327
337
  ).rejects.toSatisfy((err) => {
328
- assert(err instanceof XrpcUpstreamError)
329
- expect(err.message).toBe('Upstream server encountered an error')
338
+ assert(err instanceof XrpcResponseError)
339
+ expect(err.message).toBe('Upstream server responded with a 500 error')
330
340
  return true
331
341
  })
332
342
  })
@@ -344,7 +354,7 @@ describe(xrpc, () => {
344
354
  ).rejects.toSatisfy((err) => {
345
355
  assert(err instanceof XrpcResponseError)
346
356
  expect(err.status).toBe(502)
347
- expect(err.body).toEqual({
357
+ expect(err.toJSON()).toEqual({
348
358
  error: 'ServerError',
349
359
  message: 'Something went wrong',
350
360
  })
@@ -354,7 +364,7 @@ describe(xrpc, () => {
354
364
  })
355
365
 
356
366
  describe('invalid response errors', () => {
357
- it('throws XrpcInvalidResponseError when response body fails validation', async () => {
367
+ it('throws XrpcResponseValidationError when response body fails validation', async () => {
358
368
  // Schema expects { value: string } but we return { value: 123 }
359
369
  const fetchHandler = vi.fn<FetchHandler>(async () => {
360
370
  return Response.json({ value: 123 })
@@ -363,14 +373,14 @@ describe(xrpc, () => {
363
373
  await expect(
364
374
  xrpc(fetchHandler, testQuery, { params: { limit: 10 } }),
365
375
  ).rejects.toSatisfy((err) => {
366
- assert(err instanceof XrpcInvalidResponseError)
367
- expect(err).toBeInstanceOf(XrpcUpstreamError)
376
+ assert(err instanceof XrpcResponseValidationError)
377
+ expect(err).toBeInstanceOf(XrpcInvalidResponseError)
368
378
  expect(err.cause).toBeInstanceOf(Error)
369
379
  return true
370
380
  })
371
381
  })
372
382
 
373
- it('throws XrpcUpstreamError when response has wrong content-type', async () => {
383
+ it('throws XrpcInvalidResponseError when response has wrong content-type', async () => {
374
384
  const fetchHandler = vi.fn<FetchHandler>(async () => {
375
385
  return new Response('binary data', {
376
386
  status: 200,
@@ -381,7 +391,7 @@ describe(xrpc, () => {
381
391
  await expect(
382
392
  xrpc(fetchHandler, testQuery, { params: { limit: 10 } }),
383
393
  ).rejects.toSatisfy((err) => {
384
- assert(err instanceof XrpcUpstreamError)
394
+ assert(err instanceof XrpcInvalidResponseError)
385
395
  expect(err.message).toContain('application/json')
386
396
  return true
387
397
  })
@@ -408,7 +418,7 @@ describe(xrpc, () => {
408
418
  })
409
419
 
410
420
  describe('response payload parsing', () => {
411
- it('throws XrpcUpstreamError when error response body cannot be parsed', async () => {
421
+ it('throws XrpcInvalidResponseError when error response body cannot be parsed', async () => {
412
422
  const fetchHandler = vi.fn<FetchHandler>(async () => {
413
423
  return new Response('not valid json', {
414
424
  status: 400,
@@ -419,7 +429,7 @@ describe(xrpc, () => {
419
429
  await expect(
420
430
  xrpc(fetchHandler, testQuery, { params: { limit: 10 } }),
421
431
  ).rejects.toSatisfy((err) => {
422
- assert(err instanceof XrpcUpstreamError)
432
+ assert(err instanceof XrpcInvalidResponseError)
423
433
  expect(err.message).toMatch('Unable to parse response payload')
424
434
  assert(err.cause instanceof Error)
425
435
  expect(err.cause.message).toContain('Unexpected token')
@@ -427,7 +437,7 @@ describe(xrpc, () => {
427
437
  })
428
438
  })
429
439
 
430
- it('throws XrpcUpstreamError when success response body cannot be parsed', async () => {
440
+ it('throws XrpcInvalidResponseError when success response body cannot be parsed', async () => {
431
441
  const fetchHandler = vi.fn<FetchHandler>(async () => {
432
442
  return new Response('not valid json', {
433
443
  status: 200,
@@ -438,7 +448,7 @@ describe(xrpc, () => {
438
448
  await expect(
439
449
  xrpc(fetchHandler, testQuery, { params: { limit: 10 } }),
440
450
  ).rejects.toSatisfy((err) => {
441
- assert(err instanceof XrpcUpstreamError)
451
+ assert(err instanceof XrpcInvalidResponseError)
442
452
  expect(err.message).toMatch('Unable to parse response payload')
443
453
  assert(err.cause instanceof Error)
444
454
  expect(err.cause.message).toContain('Unexpected token')
@@ -446,21 +456,7 @@ describe(xrpc, () => {
446
456
  })
447
457
  })
448
458
 
449
- it('throws XrpcUpstreamError when schema expects no payload but got one', async () => {
450
- const fetchHandler = vi.fn<FetchHandler>(async () => {
451
- return Response.json({ unexpected: 'data' })
452
- })
453
-
454
- await expect(xrpc(fetchHandler, testNoOutputQuery)).rejects.toSatisfy(
455
- (err) => {
456
- assert(err instanceof XrpcUpstreamError)
457
- expect(err.message).toContain('no body')
458
- return true
459
- },
460
- )
461
- })
462
-
463
- it('throws XrpcUpstreamError when schema expects payload but response is empty', async () => {
459
+ it('throws XrpcInvalidResponseError when schema expects payload but response is empty', async () => {
464
460
  const fetchHandler = vi.fn<FetchHandler>(async () => {
465
461
  return new Response(null, { status: 200 })
466
462
  })
@@ -468,8 +464,8 @@ describe(xrpc, () => {
468
464
  await expect(
469
465
  xrpc(fetchHandler, testQuery, { params: { limit: 10 } }),
470
466
  ).rejects.toSatisfy((err) => {
471
- assert(err instanceof XrpcUpstreamError)
472
- expect(err.message).toContain('non-empty response')
467
+ assert(err instanceof XrpcInvalidResponseError)
468
+ expect(err.message).toContain('got no payload')
473
469
  return true
474
470
  })
475
471
  })
@@ -516,15 +512,15 @@ describe(xrpc, () => {
516
512
  })
517
513
 
518
514
  describe('non-2xx non-4xx/5xx responses', () => {
519
- it('throws XrpcUpstreamError for 3xx status codes', async () => {
515
+ it('throws XrpcInvalidResponseError for 3xx status codes', async () => {
520
516
  const fetchHandler: FetchHandler = async () =>
521
517
  Response.json({ value: 'redirect' }, { status: 302 })
522
518
 
523
519
  await expect(
524
520
  xrpc(fetchHandler, testQuery, { params: { limit: 10 } }),
525
521
  ).rejects.toSatisfy((err) => {
526
- assert(err instanceof XrpcUpstreamError)
527
- expect(err.message).toBe('Invalid response status code')
522
+ assert(err instanceof XrpcInvalidResponseError)
523
+ expect(err.message).toBe('Unexpected status code 302')
528
524
  return true
529
525
  })
530
526
  })
@@ -606,8 +602,8 @@ describe(xrpc, () => {
606
602
  await expect(
607
603
  xrpc(fetchHandler, testQuery, { params: { limit: 10 } }),
608
604
  ).rejects.toSatisfy((err) => {
609
- assert(err instanceof XrpcInvalidResponseError)
610
- expect(err).toBeInstanceOf(XrpcUpstreamError)
605
+ assert(err instanceof XrpcResponseValidationError)
606
+ expect(err).toBeInstanceOf(XrpcInvalidResponseError)
611
607
  return true
612
608
  })
613
609
  })
@@ -660,7 +656,7 @@ describe(xrpc, () => {
660
656
  await expect(
661
657
  xrpc(validWithFloatHandler, testQuery, { params: { limit: 10 } }),
662
658
  ).rejects.toSatisfy((err) => {
663
- assert(err instanceof XrpcUpstreamError)
659
+ assert(err instanceof XrpcInvalidResponseError)
664
660
  expect(err.message).toMatch('Unable to parse response payload')
665
661
  expect(err.cause).toBeInstanceOf(TypeError)
666
662
  return true
@@ -683,7 +679,7 @@ describe(xrpc, () => {
683
679
  strictResponseProcessing: true,
684
680
  }),
685
681
  ).rejects.toSatisfy((err) => {
686
- assert(err instanceof XrpcUpstreamError)
682
+ assert(err instanceof XrpcInvalidResponseError)
687
683
  expect(err.message).toMatch('Unable to parse response payload')
688
684
  expect(err.cause).toBeInstanceOf(TypeError)
689
685
  return true
@@ -693,8 +689,8 @@ describe(xrpc, () => {
693
689
  it('rejects error response with invalid lex data by default', async () => {
694
690
  await expect(xrpc(errorWithFloatHandler, testQuery)).rejects.toSatisfy(
695
691
  (err) => {
696
- assert(err instanceof XrpcUpstreamError)
697
- expect(err.message).toMatch('Unable to parse response payload')
692
+ assert(err instanceof XrpcResponseError)
693
+ expect(err.message).toBe('test-error-description')
698
694
  return true
699
695
  },
700
696
  )
@@ -710,7 +706,7 @@ describe(xrpc, () => {
710
706
  // Error response is still an error, but it should be parsed successfully
711
707
  assert(err instanceof XrpcResponseError)
712
708
  expect(err.status).toBe(400)
713
- expect(err.payload.body).toEqual({
709
+ expect(err.payload?.body).toEqual({
714
710
  error: 'TestError',
715
711
  message: 'test-error-description',
716
712
  extra: 1.5,
@@ -731,8 +727,8 @@ describe(xrpc, () => {
731
727
  validateResponse: true,
732
728
  }),
733
729
  ).rejects.toSatisfy((err) => {
734
- assert(err instanceof XrpcInvalidResponseError)
735
- expect(err).toBeInstanceOf(XrpcUpstreamError)
730
+ assert(err instanceof XrpcResponseValidationError)
731
+ expect(err).toBeInstanceOf(XrpcInvalidResponseError)
736
732
  return true
737
733
  })
738
734
  })
@@ -778,7 +774,7 @@ describe(xrpc, () => {
778
774
  validateResponse: false,
779
775
  }),
780
776
  ).rejects.toSatisfy((err) => {
781
- assert(err instanceof XrpcUpstreamError)
777
+ assert(err instanceof XrpcInvalidResponseError)
782
778
  expect(err.message).toMatch('Unable to parse response payload')
783
779
  return true
784
780
  })
@@ -925,8 +921,8 @@ describe(xrpcSafe, () => {
925
921
 
926
922
  assert(!result.success)
927
923
  assert(result instanceof XrpcResponseError)
928
- expect(result.status).toBe(400)
929
- expect(result.body).toEqual({
924
+ expect(result.response.status).toBe(400)
925
+ expect(result.toJSON()).toEqual({
930
926
  error: 'TestError',
931
927
  message: 'bad request',
932
928
  })
@@ -946,10 +942,10 @@ describe(xrpcSafe, () => {
946
942
  assert(!result.success)
947
943
  assert(result instanceof XrpcResponseError)
948
944
  expect(result).toBeInstanceOf(XrpcAuthenticationError)
949
- expect(result.status).toBe(401)
945
+ expect(result.response.status).toBe(401)
950
946
  })
951
947
 
952
- it('returns XrpcUpstreamError for non-XRPC error response', async () => {
948
+ it('returns XrpcResponseError for non-XRPC error response', async () => {
953
949
  const fetchHandler: FetchHandler = async () =>
954
950
  new Response('Not Found', {
955
951
  status: 404,
@@ -961,10 +957,10 @@ describe(xrpcSafe, () => {
961
957
  })
962
958
 
963
959
  assert(!result.success)
964
- expect(result).toBeInstanceOf(XrpcUpstreamError)
960
+ expect(result).toBeInstanceOf(XrpcResponseError)
965
961
  })
966
962
 
967
- it('returns XrpcUpstreamError for 500 without valid error payload', async () => {
963
+ it('returns XrpcResponseError for 500 without valid error payload', async () => {
968
964
  const fetchHandler: FetchHandler = async () =>
969
965
  new Response('Internal Server Error', {
970
966
  status: 500,
@@ -976,12 +972,16 @@ describe(xrpcSafe, () => {
976
972
  })
977
973
 
978
974
  assert(!result.success)
979
- expect(result).toBeInstanceOf(XrpcUpstreamError)
975
+ expect(result).toBeInstanceOf(XrpcResponseError)
976
+ expect(result.error).toBe('InternalServerError')
977
+ expect(result.message).toMatch(
978
+ 'Upstream server responded with a 500 error',
979
+ )
980
980
  })
981
981
  })
982
982
 
983
983
  describe('invalid response errors', () => {
984
- it('returns XrpcInvalidResponseError when response body fails validation', async () => {
984
+ it('returns XrpcResponseValidationError when response body fails validation', async () => {
985
985
  const fetchHandler: FetchHandler = async () =>
986
986
  Response.json({ value: 123 })
987
987
 
@@ -990,11 +990,11 @@ describe(xrpcSafe, () => {
990
990
  })
991
991
 
992
992
  assert(!result.success)
993
+ expect(result).toBeInstanceOf(XrpcResponseValidationError)
993
994
  expect(result).toBeInstanceOf(XrpcInvalidResponseError)
994
- expect(result).toBeInstanceOf(XrpcUpstreamError)
995
995
  })
996
996
 
997
- it('returns XrpcUpstreamError when response has wrong content-type', async () => {
997
+ it('returns XrpcInvalidResponseError when response has wrong content-type', async () => {
998
998
  const fetchHandler: FetchHandler = async () =>
999
999
  new Response('binary data', {
1000
1000
  status: 200,
@@ -1006,7 +1006,7 @@ describe(xrpcSafe, () => {
1006
1006
  })
1007
1007
 
1008
1008
  assert(!result.success)
1009
- expect(result).toBeInstanceOf(XrpcUpstreamError)
1009
+ expect(result).toBeInstanceOf(XrpcInvalidResponseError)
1010
1010
  })
1011
1011
  })
1012
1012
 
@@ -1042,6 +1042,7 @@ describe(xrpcSafe, () => {
1042
1042
  assert(!result.success)
1043
1043
  expect(result).toBeInstanceOf(XrpcInternalError)
1044
1044
  expect(result).not.toBeInstanceOf(XrpcFetchError)
1045
+ expect(fetchHandler).not.toHaveBeenCalled()
1045
1046
  })
1046
1047
 
1047
1048
  it('returns XrpcInternalError for invalid body when enabled', async () => {
@@ -1088,7 +1089,7 @@ describe(xrpcSafe, () => {
1088
1089
  })
1089
1090
 
1090
1091
  describe('validateResponse', () => {
1091
- it('returns XrpcInvalidResponseError for invalid body by default', async () => {
1092
+ it('returns XrpcResponseValidationError for invalid body by default', async () => {
1092
1093
  const fetchHandler = vi.fn<FetchHandler>(async () => {
1093
1094
  return Response.json({ value: 123 })
1094
1095
  })
@@ -1098,8 +1099,8 @@ describe(xrpcSafe, () => {
1098
1099
  })
1099
1100
 
1100
1101
  assert(!result.success)
1102
+ expect(result).toBeInstanceOf(XrpcResponseValidationError)
1101
1103
  expect(result).toBeInstanceOf(XrpcInvalidResponseError)
1102
- expect(result).toBeInstanceOf(XrpcUpstreamError)
1103
1104
  })
1104
1105
 
1105
1106
  it('accepts invalid response body when disabled', async () => {
@@ -1164,7 +1165,7 @@ describe(xrpcSafe, () => {
1164
1165
 
1165
1166
  const result = await xrpcSafe(fetchHandler, testQueryGetBlobRef)
1166
1167
  assert(!result.success)
1167
- expect(result).toBeInstanceOf(XrpcUpstreamError)
1168
+ expect(result).toBeInstanceOf(XrpcInvalidResponseError)
1168
1169
  expect(result.message).toMatch('Unable to parse response payload')
1169
1170
  assert(result.cause instanceof TypeError)
1170
1171
  expect(result.cause.message).toBe('Invalid blob object')
@@ -1187,7 +1188,7 @@ describe(xrpcSafe, () => {
1187
1188
 
1188
1189
  const result = await xrpcSafe(fetchHandler, testQueryGetBlobRef)
1189
1190
  assert(!result.success)
1190
- expect(result).toBeInstanceOf(XrpcUpstreamError)
1191
+ expect(result).toBeInstanceOf(XrpcInvalidResponseError)
1191
1192
  expect(result.message).toMatch('Unable to parse response payload')
1192
1193
  assert(result.cause instanceof TypeError)
1193
1194
  expect(result.cause.message).toBe('Invalid blob object')
@@ -1209,9 +1210,9 @@ describe(xrpcSafe, () => {
1209
1210
 
1210
1211
  const result = await xrpcSafe(fetchHandler, testQueryGetBlobRef)
1211
1212
  assert(!result.success)
1212
- expect(result).toBeInstanceOf(XrpcUpstreamError)
1213
+ expect(result).toBeInstanceOf(XrpcInvalidResponseError)
1213
1214
  expect(result.message).toBe(
1214
- 'Invalid response: Expected "image/png" (got "invalid/mime") at $.blobRef.mimeType',
1215
+ 'Invalid response payload: Expected "image/png" (got "invalid/mime") at $.blobRef.mimeType',
1215
1216
  )
1216
1217
  })
1217
1218
 
@@ -1231,9 +1232,9 @@ describe(xrpcSafe, () => {
1231
1232
 
1232
1233
  const result = await xrpcSafe(fetchHandler, testQueryGetBlobRef)
1233
1234
  assert(!result.success)
1234
- expect(result).toBeInstanceOf(XrpcUpstreamError)
1235
+ expect(result).toBeInstanceOf(XrpcInvalidResponseError)
1235
1236
  expect(result.message).toBe(
1236
- 'Invalid response: blob too big (maximum 10, got 100) at $.blobRef',
1237
+ 'Invalid response payload: blob too big (maximum 10, got 100) at $.blobRef',
1237
1238
  )
1238
1239
  })
1239
1240
 
@@ -1256,7 +1257,7 @@ describe(xrpcSafe, () => {
1256
1257
  })
1257
1258
 
1258
1259
  assert(result.success)
1259
- expectTypeOf(result.body).toMatchObjectType<{ blobRef: l.BlobRef }>()
1260
+ expectTypeOf(result.body).toEqualTypeOf<{ blobRef: l.BlobRef }>()
1260
1261
  expect(result.body).toEqual({
1261
1262
  blobRef: {
1262
1263
  $type: 'blob',
@@ -1282,13 +1283,11 @@ describe(xrpcSafe, () => {
1282
1283
  })
1283
1284
 
1284
1285
  assert(result.success)
1285
- expectTypeOf(result.body).toMatchObjectType<{ blobRef: l.BlobRef }>()
1286
+ expectTypeOf(result.body).toEqualTypeOf<{ blobRef: l.BlobRef }>()
1286
1287
  expect(result.body).toEqual({
1287
1288
  blobRef: {
1288
- $type: 'blob',
1289
- ref: rawCid,
1289
+ cid: rawCid.toString(),
1290
1290
  mimeType: 'invalid/mime',
1291
- size: -1,
1292
1291
  },
1293
1292
  })
1294
1293
  })
@@ -1310,7 +1309,7 @@ describe(xrpcSafe, () => {
1310
1309
  })
1311
1310
 
1312
1311
  assert(result.success)
1313
- expectTypeOf(result.body).toMatchObjectType<{ blobRef: l.BlobRef }>()
1312
+ expectTypeOf(result.body).toEqualTypeOf<{ blobRef: l.BlobRef }>()
1314
1313
  expect(result.body).toEqual({
1315
1314
  blobRef: {
1316
1315
  $type: 'blob',
@@ -1342,7 +1341,7 @@ describe(xrpcSafe, () => {
1342
1341
  })
1343
1342
 
1344
1343
  assert(!result.success)
1345
- expect(result).toBeInstanceOf(XrpcUpstreamError)
1344
+ expect(result).toBeInstanceOf(XrpcInvalidResponseError)
1346
1345
  expect(result.message).toMatch('Unable to parse response payload')
1347
1346
  assert(result.cause instanceof TypeError)
1348
1347
  expect(result.cause.message).toBe('Invalid non-integer number: 1.5')
@@ -1369,7 +1368,7 @@ describe(xrpcSafe, () => {
1369
1368
  })
1370
1369
 
1371
1370
  assert(!result.success)
1372
- expect(result).toBeInstanceOf(XrpcUpstreamError)
1371
+ expect(result).toBeInstanceOf(XrpcInvalidResponseError)
1373
1372
  expect(result.message).toMatch('Unable to parse response payload')
1374
1373
  assert(result.cause instanceof TypeError)
1375
1374
  expect(result.cause.message).toBe('Invalid non-integer number: 1.5')
@@ -1383,10 +1382,8 @@ describe(xrpcSafe, () => {
1383
1382
  })
1384
1383
 
1385
1384
  assert(!result.success)
1386
- expect(result).toBeInstanceOf(XrpcUpstreamError)
1387
- expect(result.message).toMatch('Unable to parse response payload')
1388
- assert(result.cause instanceof TypeError)
1389
- expect(result.cause.message).toBe('Invalid non-integer number: 1.5')
1385
+ expect(result).toBeInstanceOf(XrpcResponseError)
1386
+ expect(result.message).toBe('test-error-description')
1390
1387
  })
1391
1388
 
1392
1389
  it('parses error response with invalid lex data when strict processing is disabled', async () => {
@@ -1399,7 +1396,7 @@ describe(xrpcSafe, () => {
1399
1396
 
1400
1397
  assert(!result.success)
1401
1398
  assert(result instanceof XrpcResponseError)
1402
- expect(result.status).toBe(400)
1399
+ expect(result.response.status).toBe(400)
1403
1400
  expect(result.message).toBe('test-error-description')
1404
1401
  })
1405
1402
 
@@ -1415,8 +1412,8 @@ describe(xrpcSafe, () => {
1415
1412
  })
1416
1413
 
1417
1414
  assert(!result.success)
1415
+ expect(result).toBeInstanceOf(XrpcResponseValidationError)
1418
1416
  expect(result).toBeInstanceOf(XrpcInvalidResponseError)
1419
- expect(result).toBeInstanceOf(XrpcUpstreamError)
1420
1417
  })
1421
1418
 
1422
1419
  it('with strictResponseProcessing: false and validateResponse: false, schema validation is skipped', async () => {
@@ -1444,7 +1441,7 @@ describe(xrpcSafe, () => {
1444
1441
  })
1445
1442
 
1446
1443
  assert(!result.success)
1447
- expect(result).toBeInstanceOf(XrpcUpstreamError)
1444
+ expect(result).toBeInstanceOf(XrpcInvalidResponseError)
1448
1445
  expect(result.message).toMatch('Unable to parse response payload')
1449
1446
  assert(result.cause instanceof TypeError)
1450
1447
  expect(result.cause.message).toBe('Invalid non-integer number: 1.5')
package/src/xrpc.ts CHANGED
@@ -360,9 +360,7 @@ function buildPayload(
360
360
  ): null | { body: BodyInit; encoding: string } {
361
361
  if (schema.encoding === undefined) {
362
362
  if (body !== undefined) {
363
- throw new TypeError(
364
- `Cannot send a ${typeof body} body with undefined encoding`,
365
- )
363
+ throw new TypeError(`Endpoint expects no payload`)
366
364
  }
367
365
 
368
366
  return null