pmxtjs 2.20.3 → 2.21.0

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.
@@ -11,6 +11,7 @@ const index_js_1 = require("../generated/src/index.js");
11
11
  const models_js_1 = require("./models.js");
12
12
  const server_manager_js_1 = require("./server-manager.js");
13
13
  const args_js_1 = require("./args.js");
14
+ const errors_js_1 = require("./errors.js");
14
15
  // Converter functions
15
16
  function convertMarket(raw) {
16
17
  const outcomes = (raw.outcomes || []).map((o) => ({
@@ -207,7 +208,7 @@ class Exchange {
207
208
  this.api = new index_js_1.DefaultApi(this.config);
208
209
  }
209
210
  catch (error) {
210
- throw new Error(`Failed to start PMXT server: ${error}\n\n` +
211
+ throw new errors_js_1.PmxtError(`Failed to start PMXT server: ${error}\n\n` +
211
212
  `Please ensure 'pmxt-core' is installed: npm install -g pmxt-core\n` +
212
213
  `Or start the server manually: pmxt-server`);
213
214
  }
@@ -216,7 +217,10 @@ class Exchange {
216
217
  handleResponse(response) {
217
218
  if (!response.success) {
218
219
  const error = response.error || {};
219
- throw new Error(error.message || "Unknown error");
220
+ if (error && typeof error === "object" && (error.code || error.message)) {
221
+ throw (0, errors_js_1.fromServerError)(error);
222
+ }
223
+ throw new errors_js_1.PmxtError(error.message || "Unknown error");
220
224
  }
221
225
  return response.data;
222
226
  }
@@ -272,14 +276,19 @@ class Exchange {
272
276
  body: JSON.stringify(requestBody)
273
277
  });
274
278
  if (!response.ok) {
275
- const error = await response.json().catch(() => ({}));
276
- throw new Error(error.error?.message || response.statusText);
279
+ const body = await response.json().catch(() => ({}));
280
+ if (body.error && typeof body.error === "object") {
281
+ throw (0, errors_js_1.fromServerError)(body.error);
282
+ }
283
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
277
284
  }
278
285
  const json = await response.json();
279
286
  return this.handleResponse(json);
280
287
  }
281
288
  catch (error) {
282
- throw new Error(`Failed to call API '${operationId}': ${error}`);
289
+ if (error instanceof errors_js_1.PmxtError)
290
+ throw error;
291
+ throw new errors_js_1.PmxtError(`Failed to call API '${operationId}': ${error}`);
283
292
  }
284
293
  }
285
294
  // BEGIN GENERATED METHODS
@@ -294,8 +303,11 @@ class Exchange {
294
303
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
295
304
  });
296
305
  if (!response.ok) {
297
- const error = await response.json().catch(() => ({}));
298
- throw new Error(error.error?.message || response.statusText);
306
+ const body = await response.json().catch(() => ({}));
307
+ if (body.error && typeof body.error === "object") {
308
+ throw (0, errors_js_1.fromServerError)(body.error);
309
+ }
310
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
299
311
  }
300
312
  const json = await response.json();
301
313
  const data = this.handleResponse(json);
@@ -306,7 +318,9 @@ class Exchange {
306
318
  return result;
307
319
  }
308
320
  catch (error) {
309
- throw new Error(`Failed to loadMarkets: ${error}`);
321
+ if (error instanceof errors_js_1.PmxtError)
322
+ throw error;
323
+ throw new errors_js_1.PmxtError(`Failed to loadMarkets: ${error}`);
310
324
  }
311
325
  }
312
326
  async fetchMarkets(params) {
@@ -319,15 +333,20 @@ class Exchange {
319
333
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
320
334
  });
321
335
  if (!response.ok) {
322
- const error = await response.json().catch(() => ({}));
323
- throw new Error(error.error?.message || response.statusText);
336
+ const body = await response.json().catch(() => ({}));
337
+ if (body.error && typeof body.error === "object") {
338
+ throw (0, errors_js_1.fromServerError)(body.error);
339
+ }
340
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
324
341
  }
325
342
  const json = await response.json();
326
343
  const data = this.handleResponse(json);
327
344
  return data.map(convertMarket);
328
345
  }
329
346
  catch (error) {
330
- throw new Error(`Failed to fetchMarkets: ${error}`);
347
+ if (error instanceof errors_js_1.PmxtError)
348
+ throw error;
349
+ throw new errors_js_1.PmxtError(`Failed to fetchMarkets: ${error}`);
331
350
  }
332
351
  }
333
352
  async fetchMarketsPaginated(params) {
@@ -340,8 +359,11 @@ class Exchange {
340
359
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
341
360
  });
342
361
  if (!response.ok) {
343
- const error = await response.json().catch(() => ({}));
344
- throw new Error(error.error?.message || response.statusText);
362
+ const body = await response.json().catch(() => ({}));
363
+ if (body.error && typeof body.error === "object") {
364
+ throw (0, errors_js_1.fromServerError)(body.error);
365
+ }
366
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
345
367
  }
346
368
  const json = await response.json();
347
369
  const data = this.handleResponse(json);
@@ -352,7 +374,9 @@ class Exchange {
352
374
  };
353
375
  }
354
376
  catch (error) {
355
- throw new Error(`Failed to fetchMarketsPaginated: ${error}`);
377
+ if (error instanceof errors_js_1.PmxtError)
378
+ throw error;
379
+ throw new errors_js_1.PmxtError(`Failed to fetchMarketsPaginated: ${error}`);
356
380
  }
357
381
  }
358
382
  async fetchEvents(params) {
@@ -365,15 +389,20 @@ class Exchange {
365
389
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
366
390
  });
367
391
  if (!response.ok) {
368
- const error = await response.json().catch(() => ({}));
369
- throw new Error(error.error?.message || response.statusText);
392
+ const body = await response.json().catch(() => ({}));
393
+ if (body.error && typeof body.error === "object") {
394
+ throw (0, errors_js_1.fromServerError)(body.error);
395
+ }
396
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
370
397
  }
371
398
  const json = await response.json();
372
399
  const data = this.handleResponse(json);
373
400
  return data.map(convertEvent);
374
401
  }
375
402
  catch (error) {
376
- throw new Error(`Failed to fetchEvents: ${error}`);
403
+ if (error instanceof errors_js_1.PmxtError)
404
+ throw error;
405
+ throw new errors_js_1.PmxtError(`Failed to fetchEvents: ${error}`);
377
406
  }
378
407
  }
379
408
  async fetchMarket(params) {
@@ -386,15 +415,20 @@ class Exchange {
386
415
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
387
416
  });
388
417
  if (!response.ok) {
389
- const error = await response.json().catch(() => ({}));
390
- throw new Error(error.error?.message || response.statusText);
418
+ const body = await response.json().catch(() => ({}));
419
+ if (body.error && typeof body.error === "object") {
420
+ throw (0, errors_js_1.fromServerError)(body.error);
421
+ }
422
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
391
423
  }
392
424
  const json = await response.json();
393
425
  const data = this.handleResponse(json);
394
426
  return convertMarket(data);
395
427
  }
396
428
  catch (error) {
397
- throw new Error(`Failed to fetchMarket: ${error}`);
429
+ if (error instanceof errors_js_1.PmxtError)
430
+ throw error;
431
+ throw new errors_js_1.PmxtError(`Failed to fetchMarket: ${error}`);
398
432
  }
399
433
  }
400
434
  async fetchEvent(params) {
@@ -407,15 +441,20 @@ class Exchange {
407
441
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
408
442
  });
409
443
  if (!response.ok) {
410
- const error = await response.json().catch(() => ({}));
411
- throw new Error(error.error?.message || response.statusText);
444
+ const body = await response.json().catch(() => ({}));
445
+ if (body.error && typeof body.error === "object") {
446
+ throw (0, errors_js_1.fromServerError)(body.error);
447
+ }
448
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
412
449
  }
413
450
  const json = await response.json();
414
451
  const data = this.handleResponse(json);
415
452
  return convertEvent(data);
416
453
  }
417
454
  catch (error) {
418
- throw new Error(`Failed to fetchEvent: ${error}`);
455
+ if (error instanceof errors_js_1.PmxtError)
456
+ throw error;
457
+ throw new errors_js_1.PmxtError(`Failed to fetchEvent: ${error}`);
419
458
  }
420
459
  }
421
460
  async fetchOrderBook(id) {
@@ -429,15 +468,20 @@ class Exchange {
429
468
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
430
469
  });
431
470
  if (!response.ok) {
432
- const error = await response.json().catch(() => ({}));
433
- throw new Error(error.error?.message || response.statusText);
471
+ const body = await response.json().catch(() => ({}));
472
+ if (body.error && typeof body.error === "object") {
473
+ throw (0, errors_js_1.fromServerError)(body.error);
474
+ }
475
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
434
476
  }
435
477
  const json = await response.json();
436
478
  const data = this.handleResponse(json);
437
479
  return convertOrderBook(data);
438
480
  }
439
481
  catch (error) {
440
- throw new Error(`Failed to fetchOrderBook: ${error}`);
482
+ if (error instanceof errors_js_1.PmxtError)
483
+ throw error;
484
+ throw new errors_js_1.PmxtError(`Failed to fetchOrderBook: ${error}`);
441
485
  }
442
486
  }
443
487
  async cancelOrder(orderId) {
@@ -451,15 +495,20 @@ class Exchange {
451
495
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
452
496
  });
453
497
  if (!response.ok) {
454
- const error = await response.json().catch(() => ({}));
455
- throw new Error(error.error?.message || response.statusText);
498
+ const body = await response.json().catch(() => ({}));
499
+ if (body.error && typeof body.error === "object") {
500
+ throw (0, errors_js_1.fromServerError)(body.error);
501
+ }
502
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
456
503
  }
457
504
  const json = await response.json();
458
505
  const data = this.handleResponse(json);
459
506
  return convertOrder(data);
460
507
  }
461
508
  catch (error) {
462
- throw new Error(`Failed to cancelOrder: ${error}`);
509
+ if (error instanceof errors_js_1.PmxtError)
510
+ throw error;
511
+ throw new errors_js_1.PmxtError(`Failed to cancelOrder: ${error}`);
463
512
  }
464
513
  }
465
514
  async fetchOrder(orderId) {
@@ -473,15 +522,20 @@ class Exchange {
473
522
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
474
523
  });
475
524
  if (!response.ok) {
476
- const error = await response.json().catch(() => ({}));
477
- throw new Error(error.error?.message || response.statusText);
525
+ const body = await response.json().catch(() => ({}));
526
+ if (body.error && typeof body.error === "object") {
527
+ throw (0, errors_js_1.fromServerError)(body.error);
528
+ }
529
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
478
530
  }
479
531
  const json = await response.json();
480
532
  const data = this.handleResponse(json);
481
533
  return convertOrder(data);
482
534
  }
483
535
  catch (error) {
484
- throw new Error(`Failed to fetchOrder: ${error}`);
536
+ if (error instanceof errors_js_1.PmxtError)
537
+ throw error;
538
+ throw new errors_js_1.PmxtError(`Failed to fetchOrder: ${error}`);
485
539
  }
486
540
  }
487
541
  async fetchOpenOrders(marketId) {
@@ -494,15 +548,20 @@ class Exchange {
494
548
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
495
549
  });
496
550
  if (!response.ok) {
497
- const error = await response.json().catch(() => ({}));
498
- throw new Error(error.error?.message || response.statusText);
551
+ const body = await response.json().catch(() => ({}));
552
+ if (body.error && typeof body.error === "object") {
553
+ throw (0, errors_js_1.fromServerError)(body.error);
554
+ }
555
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
499
556
  }
500
557
  const json = await response.json();
501
558
  const data = this.handleResponse(json);
502
559
  return data.map(convertOrder);
503
560
  }
504
561
  catch (error) {
505
- throw new Error(`Failed to fetchOpenOrders: ${error}`);
562
+ if (error instanceof errors_js_1.PmxtError)
563
+ throw error;
564
+ throw new errors_js_1.PmxtError(`Failed to fetchOpenOrders: ${error}`);
506
565
  }
507
566
  }
508
567
  async fetchMyTrades(params) {
@@ -515,15 +574,20 @@ class Exchange {
515
574
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
516
575
  });
517
576
  if (!response.ok) {
518
- const error = await response.json().catch(() => ({}));
519
- throw new Error(error.error?.message || response.statusText);
577
+ const body = await response.json().catch(() => ({}));
578
+ if (body.error && typeof body.error === "object") {
579
+ throw (0, errors_js_1.fromServerError)(body.error);
580
+ }
581
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
520
582
  }
521
583
  const json = await response.json();
522
584
  const data = this.handleResponse(json);
523
585
  return data.map(convertUserTrade);
524
586
  }
525
587
  catch (error) {
526
- throw new Error(`Failed to fetchMyTrades: ${error}`);
588
+ if (error instanceof errors_js_1.PmxtError)
589
+ throw error;
590
+ throw new errors_js_1.PmxtError(`Failed to fetchMyTrades: ${error}`);
527
591
  }
528
592
  }
529
593
  async fetchClosedOrders(params) {
@@ -536,15 +600,20 @@ class Exchange {
536
600
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
537
601
  });
538
602
  if (!response.ok) {
539
- const error = await response.json().catch(() => ({}));
540
- throw new Error(error.error?.message || response.statusText);
603
+ const body = await response.json().catch(() => ({}));
604
+ if (body.error && typeof body.error === "object") {
605
+ throw (0, errors_js_1.fromServerError)(body.error);
606
+ }
607
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
541
608
  }
542
609
  const json = await response.json();
543
610
  const data = this.handleResponse(json);
544
611
  return data.map(convertOrder);
545
612
  }
546
613
  catch (error) {
547
- throw new Error(`Failed to fetchClosedOrders: ${error}`);
614
+ if (error instanceof errors_js_1.PmxtError)
615
+ throw error;
616
+ throw new errors_js_1.PmxtError(`Failed to fetchClosedOrders: ${error}`);
548
617
  }
549
618
  }
550
619
  async fetchAllOrders(params) {
@@ -557,15 +626,20 @@ class Exchange {
557
626
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
558
627
  });
559
628
  if (!response.ok) {
560
- const error = await response.json().catch(() => ({}));
561
- throw new Error(error.error?.message || response.statusText);
629
+ const body = await response.json().catch(() => ({}));
630
+ if (body.error && typeof body.error === "object") {
631
+ throw (0, errors_js_1.fromServerError)(body.error);
632
+ }
633
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
562
634
  }
563
635
  const json = await response.json();
564
636
  const data = this.handleResponse(json);
565
637
  return data.map(convertOrder);
566
638
  }
567
639
  catch (error) {
568
- throw new Error(`Failed to fetchAllOrders: ${error}`);
640
+ if (error instanceof errors_js_1.PmxtError)
641
+ throw error;
642
+ throw new errors_js_1.PmxtError(`Failed to fetchAllOrders: ${error}`);
569
643
  }
570
644
  }
571
645
  async fetchPositions(address) {
@@ -578,15 +652,20 @@ class Exchange {
578
652
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
579
653
  });
580
654
  if (!response.ok) {
581
- const error = await response.json().catch(() => ({}));
582
- throw new Error(error.error?.message || response.statusText);
655
+ const body = await response.json().catch(() => ({}));
656
+ if (body.error && typeof body.error === "object") {
657
+ throw (0, errors_js_1.fromServerError)(body.error);
658
+ }
659
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
583
660
  }
584
661
  const json = await response.json();
585
662
  const data = this.handleResponse(json);
586
663
  return data.map(convertPosition);
587
664
  }
588
665
  catch (error) {
589
- throw new Error(`Failed to fetchPositions: ${error}`);
666
+ if (error instanceof errors_js_1.PmxtError)
667
+ throw error;
668
+ throw new errors_js_1.PmxtError(`Failed to fetchPositions: ${error}`);
590
669
  }
591
670
  }
592
671
  async fetchBalance(address) {
@@ -599,15 +678,20 @@ class Exchange {
599
678
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
600
679
  });
601
680
  if (!response.ok) {
602
- const error = await response.json().catch(() => ({}));
603
- throw new Error(error.error?.message || response.statusText);
681
+ const body = await response.json().catch(() => ({}));
682
+ if (body.error && typeof body.error === "object") {
683
+ throw (0, errors_js_1.fromServerError)(body.error);
684
+ }
685
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
604
686
  }
605
687
  const json = await response.json();
606
688
  const data = this.handleResponse(json);
607
689
  return data.map(convertBalance);
608
690
  }
609
691
  catch (error) {
610
- throw new Error(`Failed to fetchBalance: ${error}`);
692
+ if (error instanceof errors_js_1.PmxtError)
693
+ throw error;
694
+ throw new errors_js_1.PmxtError(`Failed to fetchBalance: ${error}`);
611
695
  }
612
696
  }
613
697
  async close() {
@@ -620,14 +704,19 @@ class Exchange {
620
704
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
621
705
  });
622
706
  if (!response.ok) {
623
- const error = await response.json().catch(() => ({}));
624
- throw new Error(error.error?.message || response.statusText);
707
+ const body = await response.json().catch(() => ({}));
708
+ if (body.error && typeof body.error === "object") {
709
+ throw (0, errors_js_1.fromServerError)(body.error);
710
+ }
711
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
625
712
  }
626
713
  const json = await response.json();
627
714
  this.handleResponse(json);
628
715
  }
629
716
  catch (error) {
630
- throw new Error(`Failed to close: ${error}`);
717
+ if (error instanceof errors_js_1.PmxtError)
718
+ throw error;
719
+ throw new errors_js_1.PmxtError(`Failed to close: ${error}`);
631
720
  }
632
721
  }
633
722
  // END GENERATED METHODS
@@ -673,7 +762,9 @@ class Exchange {
673
762
  return data.map(convertCandle);
674
763
  }
675
764
  catch (error) {
676
- throw new Error(`Failed to fetch OHLCV: ${error}`);
765
+ if (error instanceof errors_js_1.PmxtError)
766
+ throw error;
767
+ throw new errors_js_1.PmxtError(`Failed to fetch OHLCV: ${error}`);
677
768
  }
678
769
  }
679
770
  /**
@@ -704,7 +795,9 @@ class Exchange {
704
795
  return data.map(convertTrade);
705
796
  }
706
797
  catch (error) {
707
- throw new Error(`Failed to fetch trades: ${error}`);
798
+ if (error instanceof errors_js_1.PmxtError)
799
+ throw error;
800
+ throw new errors_js_1.PmxtError(`Failed to fetch trades: ${error}`);
708
801
  }
709
802
  }
710
803
  // WebSocket Streaming Methods
@@ -747,7 +840,9 @@ class Exchange {
747
840
  return convertOrderBook(data);
748
841
  }
749
842
  catch (error) {
750
- throw new Error(`Failed to watch order book: ${error}`);
843
+ if (error instanceof errors_js_1.PmxtError)
844
+ throw error;
845
+ throw new errors_js_1.PmxtError(`Failed to watch order book: ${error}`);
751
846
  }
752
847
  }
753
848
  /**
@@ -798,7 +893,9 @@ class Exchange {
798
893
  return data.map(convertTrade);
799
894
  }
800
895
  catch (error) {
801
- throw new Error(`Failed to watch trades: ${error}`);
896
+ if (error instanceof errors_js_1.PmxtError)
897
+ throw error;
898
+ throw new errors_js_1.PmxtError(`Failed to watch trades: ${error}`);
802
899
  }
803
900
  }
804
901
  /**
@@ -841,7 +938,9 @@ class Exchange {
841
938
  return convertSubscriptionSnapshot(data);
842
939
  }
843
940
  catch (error) {
844
- throw new Error(`Failed to watch address: ${error}`);
941
+ if (error instanceof errors_js_1.PmxtError)
942
+ throw error;
943
+ throw new errors_js_1.PmxtError(`Failed to watch address: ${error}`);
845
944
  }
846
945
  }
847
946
  /**
@@ -865,7 +964,9 @@ class Exchange {
865
964
  return this.handleResponse(response);
866
965
  }
867
966
  catch (error) {
868
- throw new Error(`Failed to unwatch address: ${error}`);
967
+ if (error instanceof errors_js_1.PmxtError)
968
+ throw error;
969
+ throw new errors_js_1.PmxtError(`Failed to unwatch address: ${error}`);
869
970
  }
870
971
  }
871
972
  // Trading Methods (require authentication)
@@ -912,11 +1013,11 @@ class Exchange {
912
1013
  let outcomeId = params.outcomeId;
913
1014
  if (params.outcome) {
914
1015
  if (marketId !== undefined || outcomeId !== undefined) {
915
- throw new Error("Cannot specify both 'outcome' and 'marketId'/'outcomeId'. Use one or the other.");
1016
+ throw new errors_js_1.PmxtError("Cannot specify both 'outcome' and 'marketId'/'outcomeId'. Use one or the other.");
916
1017
  }
917
1018
  const outcome = params.outcome;
918
1019
  if (!outcome.marketId) {
919
- throw new Error("outcome.marketId is not set. Ensure the outcome comes from a fetched market.");
1020
+ throw new errors_js_1.PmxtError("outcome.marketId is not set. Ensure the outcome comes from a fetched market.");
920
1021
  }
921
1022
  marketId = outcome.marketId;
922
1023
  outcomeId = outcome.outcomeId;
@@ -946,7 +1047,9 @@ class Exchange {
946
1047
  return data;
947
1048
  }
948
1049
  catch (error) {
949
- throw new Error(`Failed to build order: ${error}`);
1050
+ if (error instanceof errors_js_1.PmxtError)
1051
+ throw error;
1052
+ throw new errors_js_1.PmxtError(`Failed to build order: ${error}`);
950
1053
  }
951
1054
  }
952
1055
  /**
@@ -983,7 +1086,9 @@ class Exchange {
983
1086
  return convertOrder(data);
984
1087
  }
985
1088
  catch (error) {
986
- throw new Error(`Failed to submit order: ${error}`);
1089
+ if (error instanceof errors_js_1.PmxtError)
1090
+ throw error;
1091
+ throw new errors_js_1.PmxtError(`Failed to submit order: ${error}`);
987
1092
  }
988
1093
  }
989
1094
  /**
@@ -1012,11 +1117,11 @@ class Exchange {
1012
1117
  let outcomeId = params.outcomeId;
1013
1118
  if (params.outcome) {
1014
1119
  if (marketId !== undefined || outcomeId !== undefined) {
1015
- throw new Error("Cannot specify both 'outcome' and 'marketId'/'outcomeId'. Use one or the other.");
1120
+ throw new errors_js_1.PmxtError("Cannot specify both 'outcome' and 'marketId'/'outcomeId'. Use one or the other.");
1016
1121
  }
1017
1122
  const outcome = params.outcome;
1018
1123
  if (!outcome.marketId) {
1019
- throw new Error("outcome.marketId is not set. Ensure the outcome comes from a fetched market.");
1124
+ throw new errors_js_1.PmxtError("outcome.marketId is not set. Ensure the outcome comes from a fetched market.");
1020
1125
  }
1021
1126
  marketId = outcome.marketId;
1022
1127
  outcomeId = outcome.outcomeId;
@@ -1046,7 +1151,9 @@ class Exchange {
1046
1151
  return convertOrder(data);
1047
1152
  }
1048
1153
  catch (error) {
1049
- throw new Error(`Failed to create order: ${error}`);
1154
+ if (error instanceof errors_js_1.PmxtError)
1155
+ throw error;
1156
+ throw new errors_js_1.PmxtError(`Failed to create order: ${error}`);
1050
1157
  }
1051
1158
  }
1052
1159
  /**
@@ -1091,14 +1198,19 @@ class Exchange {
1091
1198
  body: JSON.stringify(body)
1092
1199
  });
1093
1200
  if (!response.ok) {
1094
- const error = await response.json().catch(() => ({}));
1095
- throw new Error(error.error?.message || response.statusText);
1201
+ const body = await response.json().catch(() => ({}));
1202
+ if (body.error && typeof body.error === "object") {
1203
+ throw (0, errors_js_1.fromServerError)(body.error);
1204
+ }
1205
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
1096
1206
  }
1097
1207
  const json = await response.json();
1098
1208
  return this.handleResponse(json);
1099
1209
  }
1100
1210
  catch (error) {
1101
- throw new Error(`Failed to get execution price: ${error}`);
1211
+ if (error instanceof errors_js_1.PmxtError)
1212
+ throw error;
1213
+ throw new errors_js_1.PmxtError(`Failed to get execution price: ${error}`);
1102
1214
  }
1103
1215
  }
1104
1216
  // ----------------------------------------------------------------------------
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Typed error classes for pmxt.
3
+ *
4
+ * These mirror the error hierarchy in the core TypeScript library,
5
+ * enabling users to catch specific error types.
6
+ */
7
+ export declare class PmxtError extends Error {
8
+ readonly code: string;
9
+ readonly retryable: boolean;
10
+ readonly exchange?: string;
11
+ constructor(message: string, code?: string, retryable?: boolean, exchange?: string);
12
+ }
13
+ export declare class BadRequest extends PmxtError {
14
+ constructor(message: string, exchange?: string);
15
+ }
16
+ export declare class AuthenticationError extends PmxtError {
17
+ constructor(message: string, exchange?: string);
18
+ }
19
+ export declare class PermissionDenied extends PmxtError {
20
+ constructor(message: string, exchange?: string);
21
+ }
22
+ export declare class NotFoundError extends PmxtError {
23
+ constructor(message: string, exchange?: string);
24
+ }
25
+ export declare class OrderNotFound extends NotFoundError {
26
+ constructor(orderId: string, exchange?: string);
27
+ }
28
+ export declare class MarketNotFound extends NotFoundError {
29
+ constructor(marketId: string, exchange?: string);
30
+ }
31
+ export declare class EventNotFound extends NotFoundError {
32
+ constructor(identifier: string, exchange?: string);
33
+ }
34
+ export declare class RateLimitExceeded extends PmxtError {
35
+ readonly retryAfter?: number;
36
+ constructor(message: string, retryAfter?: number, exchange?: string);
37
+ }
38
+ export declare class InvalidOrder extends PmxtError {
39
+ constructor(message: string, exchange?: string);
40
+ }
41
+ export declare class InsufficientFunds extends PmxtError {
42
+ constructor(message: string, exchange?: string);
43
+ }
44
+ export declare class ValidationError extends PmxtError {
45
+ readonly field?: string;
46
+ constructor(message: string, field?: string, exchange?: string);
47
+ }
48
+ export declare class NetworkError extends PmxtError {
49
+ constructor(message: string, exchange?: string);
50
+ }
51
+ export declare class ExchangeNotAvailable extends PmxtError {
52
+ constructor(message: string, exchange?: string);
53
+ }
54
+ /** Convert a server error response object into a typed PmxtError. */
55
+ export declare function fromServerError(errorData: any): PmxtError;