@niledatabase/server 3.0.0-alpha.39 → 3.0.0-alpha.40

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.
@@ -463,7 +463,7 @@ function Logger(config) {
463
463
 
464
464
  var getSecureCookies = function getSecureCookies(cfg) {
465
465
  var config = cfg.config;
466
- if (process.env.NILEDB_SECURECOOKIES) {
466
+ if (stringCheck(process.env.NILEDB_SECURECOOKIES)) {
467
467
  return Boolean(process.env.NILEDB_SECURECOOKIES);
468
468
  }
469
469
  return config == null ? void 0 : config.secureCookies;
@@ -473,19 +473,20 @@ var getDatabaseId = function getDatabaseId(cfg) {
473
473
  logger = cfg.logger;
474
474
  var _Logger = Logger(config, '[databaseId]'),
475
475
  info = _Logger.info;
476
- if (config != null && config.databaseId) {
477
- logger && info(logger + "[config] " + config.databaseId);
476
+ if (stringCheck(config == null ? void 0 : config.databaseId)) {
477
+ logger && info(logger + "[config] " + (config == null ? void 0 : config.databaseId));
478
478
  return String(config == null ? void 0 : config.databaseId);
479
479
  }
480
- if (process.env.NILEDB_POSTGRES_URL) {
480
+ var dbId = stringCheck(process.env.NILEDB_API_URL);
481
+ if (dbId) {
481
482
  try {
482
- var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
483
- return pgUrl.pathname.substring(1);
483
+ var pgUrl = new URL(dbId);
484
+ return pgUrl.pathname.split('/')[3];
484
485
  } catch (e) {
485
486
  // ok to fail
486
487
  }
487
488
  }
488
- logger && info(logger + "[NILEDB_ID] " + process.env.NILEDB_ID);
489
+ logger && info(logger + "[NILEDB_ID] " + String(process.env.NILEDB_ID));
489
490
  return process.env.NILEDB_ID;
490
491
  };
491
492
  var getUsername = function getUsername(cfg) {
@@ -497,13 +498,14 @@ var getUsername = function getUsername(cfg) {
497
498
  logger && info(logger + "[config] " + config.user);
498
499
  return String(config == null ? void 0 : config.user);
499
500
  }
500
- if (process.env.NILEDB_POSTGRES_URL) {
501
- var url = new URL(process.env.NILEDB_POSTGRES_URL);
501
+ var pg = stringCheck(process.env.NILEDB_POSTGRES_URL);
502
+ if (pg) {
503
+ var url = new URL(pg);
502
504
  if (url.username) {
503
505
  return url.username;
504
506
  }
505
507
  }
506
- logger && info(logger + "[NILEDB_USER] " + process.env.NILEDB_USER);
508
+ logger && info(logger + "[NILEDB_USER] " + String(process.env.NILEDB_USER));
507
509
  return process.env.NILEDB_USER;
508
510
  };
509
511
  var getPassword = function getPassword(cfg) {
@@ -512,17 +514,18 @@ var getPassword = function getPassword(cfg) {
512
514
  var log = logProtector(logger);
513
515
  var _Logger3 = Logger(config, '[password]'),
514
516
  info = _Logger3.info;
515
- if (config != null && config.password) {
516
- log && info(logger + "[config] " + config.password);
517
- return String(config.password);
517
+ if (stringCheck(config == null ? void 0 : config.password)) {
518
+ log && info(logger + "[config] " + (config == null ? void 0 : config.password));
519
+ return String(config == null ? void 0 : config.password);
518
520
  }
519
- if (process.env.NILEDB_POSTGRES_URL) {
520
- var url = new URL(process.env.NILEDB_POSTGRES_URL);
521
+ var pg = stringCheck(process.env.NILEDB_POSTGRES_URL);
522
+ if (pg) {
523
+ var url = new URL(pg);
521
524
  if (url.password) {
522
525
  return url.password;
523
526
  }
524
527
  }
525
- logger && info(logger + "[NILEDB_PASSWORD] " + process.env.NILEDB_PASSWORD);
528
+ logger && info(logger + "[NILEDB_PASSWORD] " + String(process.env.NILEDB_PASSWORD));
526
529
  return process.env.NILEDB_PASSWORD;
527
530
  };
528
531
  var getInfoBearer = function getInfoBearer(cfg) {
@@ -534,12 +537,13 @@ var getToken = function getToken(cfg) {
534
537
  logger = cfg.logger;
535
538
  var _Logger4 = Logger(config, '[token]'),
536
539
  info = _Logger4.info;
537
- if (config != null && (_config$api = config.api) != null && _config$api.token) {
540
+ if (stringCheck(config == null || (_config$api = config.api) == null ? void 0 : _config$api.token)) {
538
541
  var _config$api2, _config$api3;
539
- logger && info(logger + "[config] " + ((_config$api2 = config.api) == null ? void 0 : _config$api2.token));
540
- return String((_config$api3 = config.api) == null ? void 0 : _config$api3.token);
542
+ logger && info(logger + "[config] " + (config == null || (_config$api2 = config.api) == null ? void 0 : _config$api2.token));
543
+ return String(config == null || (_config$api3 = config.api) == null ? void 0 : _config$api3.token);
541
544
  }
542
- if (process.env.NILEDB_TOKEN) {
545
+ var token = stringCheck(process.env.NILEDB_TOKEN);
546
+ if (token) {
543
547
  logger && info(logger + "[NILEDB_TOKEN] " + process.env.NILEDB_TOKEN);
544
548
  return process.env.NILEDB_TOKEN;
545
549
  }
@@ -550,11 +554,12 @@ var getDatabaseName = function getDatabaseName(cfg) {
550
554
  logger = cfg.logger;
551
555
  var _Logger5 = Logger(config, '[databaseName]'),
552
556
  info = _Logger5.info;
553
- if (config != null && config.databaseName) {
554
- logger && info(logger + "[config] " + config.databaseName);
555
- return String(config.databaseName);
557
+ if (stringCheck(config == null ? void 0 : config.databaseName)) {
558
+ logger && info(logger + "[config] " + (config == null ? void 0 : config.databaseName));
559
+ return String(config == null ? void 0 : config.databaseName);
556
560
  }
557
- if (process.env.NILEDB_NAME) {
561
+ var name = stringCheck(process.env.NILEDB_NAME);
562
+ if (name) {
558
563
  logger && info(logger + "[NILEDB_NAME] " + process.env.NILEDB_NAME);
559
564
  return process.env.NILEDB_NAME;
560
565
  }
@@ -573,13 +578,13 @@ var getTenantId = function getTenantId(cfg) {
573
578
  logger = cfg.logger;
574
579
  var _Logger6 = Logger(config, '[tenantId]'),
575
580
  info = _Logger6.info;
576
- if (config != null && config.tenantId) {
577
- logger && info(logger + "[config] " + config.tenantId);
578
- return config.tenantId;
581
+ if (stringCheck(config == null ? void 0 : config.tenantId)) {
582
+ logger && info(logger + "[config] " + (config == null ? void 0 : config.tenantId));
583
+ return String(config == null ? void 0 : config.tenantId);
579
584
  }
580
- if (process.env.NILEDB_TENANT) {
585
+ if (stringCheck(process.env.NILEDB_TENANT)) {
581
586
  logger && info(logger + "[NILEDB_TENANT] " + process.env.NILEDB_TENANT);
582
- return process.env.NILEDB_TENANT;
587
+ return String(process.env.NILEDB_TENANT);
583
588
  }
584
589
  return null;
585
590
  };
@@ -596,14 +601,15 @@ var getBasePath = function getBasePath(cfg) {
596
601
  info = _Logger7.info,
597
602
  error = _Logger7.error;
598
603
  var basePath = config == null || (_config$api4 = config.api) == null ? void 0 : _config$api4.basePath;
599
- if (basePath) {
604
+ if (stringCheck(basePath)) {
600
605
  logger && info(logger + "[config] " + basePath);
601
606
  return basePath;
602
607
  }
603
- if (process.env.NILEDB_API_URL) {
608
+ var envUrl = stringCheck(process.env.NILEDB_API_URL);
609
+ if (envUrl) {
604
610
  logger && info(logger + "[NILEDB_API_URL] " + process.env.NILEDB_API_URL);
605
611
  try {
606
- var apiUrl = new URL(process.env.NILEDB_API_URL);
612
+ var apiUrl = new URL(envUrl);
607
613
  return apiUrl.href;
608
614
  } catch (e) {
609
615
  if (e instanceof Error) {
@@ -619,14 +625,15 @@ var getControlPlane = function getControlPlane(cfg) {
619
625
  logger = cfg.logger;
620
626
  var _Logger8 = Logger(config, '[basePath]'),
621
627
  info = _Logger8.info;
622
- if (config != null && config.configureUrl) {
623
- logger && info(logger + "[config] " + config.configureUrl);
624
- return config.configureUrl;
628
+ if (stringCheck(config == null ? void 0 : config.configureUrl)) {
629
+ logger && info(logger + "[config] " + (config == null ? void 0 : config.configureUrl));
630
+ return String(config == null ? void 0 : config.configureUrl);
625
631
  }
626
- if (process.env.NILEDB_CONFIGURE) {
632
+ var autoConfigUrl = stringCheck(process.env.NILEDB_CONFIGURE);
633
+ if (autoConfigUrl) {
627
634
  logger && info(logger + "[NILEDB_CONFIGURE] " + process.env.NILEDB_CONFIGURE);
628
635
  // backwards compatible, but not really
629
- if (!process.env.NILEDB_CONFIGURE.startsWith('http')) {
636
+ if (!autoConfigUrl.startsWith('http')) {
630
637
  return "https://" + process.env.NILEDB_CONFIGURE;
631
638
  }
632
639
  return process.env.NILEDB_CONFIGURE;
@@ -639,20 +646,22 @@ function getDbHost(cfg) {
639
646
  logger = cfg.logger;
640
647
  var _Logger9 = Logger(config, '[db.host]'),
641
648
  info = _Logger9.info;
642
- if (config != null && config.db && config.db.host) {
643
- logger && info(logger + "[config] " + (config == null ? void 0 : config.db.host));
644
- return config.db.host;
649
+ if (stringCheck((config == null ? void 0 : config.db) && config.db.host)) {
650
+ var _config$db, _config$db2;
651
+ logger && info(logger + "[config] " + (config == null || (_config$db = config.db) == null ? void 0 : _config$db.host));
652
+ return String(config == null || (_config$db2 = config.db) == null ? void 0 : _config$db2.host);
645
653
  }
646
- if (process.env.NILEDB_POSTGRES_URL) {
654
+ var pg = stringCheck(process.env.NILEDB_POSTGRES_URL);
655
+ if (pg) {
647
656
  try {
648
- var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
657
+ var pgUrl = new URL(pg);
649
658
  logger && info(logger + "[NILEDB_POSTGRES_URL] " + pgUrl.hostname);
650
659
  return pgUrl.hostname;
651
660
  } catch (e) {
652
661
  // ok to fail
653
662
  }
654
663
  }
655
- if (process.env.NILEDB_HOST) {
664
+ if (stringCheck(process.env.NILEDB_HOST)) {
656
665
  logger && info(logger + "[NILEDB_HOST] " + process.env.NILEDB_HOST);
657
666
  return process.env.NILEDB_HOST;
658
667
  }
@@ -660,23 +669,24 @@ function getDbHost(cfg) {
660
669
  return 'db.thenile.dev';
661
670
  }
662
671
  function getDbPort(cfg) {
663
- var _config$db;
672
+ var _config$db3;
664
673
  var config = cfg.config,
665
674
  logger = cfg.logger;
666
675
  var _Logger10 = Logger(config, '[db.port]'),
667
676
  info = _Logger10.info;
668
- if (config != null && (_config$db = config.db) != null && _config$db.port && config.db.port != null) {
669
- var _config$db2;
677
+ if (config != null && (_config$db3 = config.db) != null && _config$db3.port && config.db.port != null) {
678
+ var _config$db4;
670
679
  logger && info(logger + "[config] " + (config == null ? void 0 : config.db.port));
671
- return Number((_config$db2 = config.db) == null ? void 0 : _config$db2.port);
680
+ return Number((_config$db4 = config.db) == null ? void 0 : _config$db4.port);
672
681
  }
673
- if (process.env.NILEDB_PORT) {
682
+ if (stringCheck(process.env.NILEDB_PORT)) {
674
683
  logger && info(logger + "[NILEDB_PORT] " + process.env.NILEDB_PORT);
675
684
  return Number(process.env.NILEDB_PORT);
676
685
  }
677
- if (process.env.NILEDB_POSTGRES_URL) {
686
+ var pg = stringCheck(process.env.NILEDB_POSTGRES_URL);
687
+ if (pg) {
678
688
  try {
679
- var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
689
+ var pgUrl = new URL(pg);
680
690
  if (pgUrl.port) {
681
691
  return Number(pgUrl.port);
682
692
  }
@@ -691,6 +701,12 @@ function getDbPort(cfg) {
691
701
  var logProtector = function logProtector(logger) {
692
702
  return process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test' ? logger : null;
693
703
  };
704
+ var stringCheck = function stringCheck(str) {
705
+ if (str && str !== '') {
706
+ return str;
707
+ }
708
+ return;
709
+ };
694
710
 
695
711
  var _excluded$2 = ["host", "port"],
696
712
  _excluded2 = ["host", "port"];
@@ -738,7 +754,7 @@ var Config = /*#__PURE__*/function () {
738
754
  this.configure = /*#__PURE__*/function () {
739
755
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
740
756
  var _config$db, _config$api$cookieKey2, _config$api2;
741
- var _Logger, info, error, debug, envVarConfig, _ref3, host, port, dbConfig, configuredHost, configuredPort, basePath, _config$api$cookieKey, _config$api, cp, databaseName, url, res, database, possibleError, json, message, _database, apiHost, dbHost, name, id, dburl;
757
+ var _Logger, info, error, debug, envVarConfig, _ref3, host, port, dbConfig, configuredHost, configuredPort, basePath, _config$api$cookieKey, _config$api, msg, cp, databaseName, url, res, database, possibleError, json, message, _database, apiHost, dbHost, name, id, dburl;
742
758
  return _regeneratorRuntime().wrap(function _callee$(_context) {
743
759
  while (1) switch (_context.prev = _context.next) {
744
760
  case 0:
@@ -751,7 +767,7 @@ var Config = /*#__PURE__*/function () {
751
767
  configuredPort = port != null ? port : getDbPort(envVarConfig);
752
768
  basePath = getBasePath(envVarConfig);
753
769
  if (!(configuredHost && _this.databaseName && _this.databaseId && basePath)) {
754
- _context.next = 12;
770
+ _context.next = 14;
755
771
  break;
756
772
  }
757
773
  info('Already configured, aborting fetch');
@@ -774,7 +790,22 @@ var Config = /*#__PURE__*/function () {
774
790
  api: _this.api
775
791
  });
776
792
  return _context.abrupt("return", _this);
777
- case 12:
793
+ case 14:
794
+ msg = [];
795
+ if (!configuredHost) {
796
+ msg.push('Database host');
797
+ }
798
+ if (!_this.databaseName) {
799
+ msg.push('Database name');
800
+ }
801
+ if (!_this.databaseId) {
802
+ msg.push('Database id');
803
+ }
804
+ if (!basePath) {
805
+ msg.push('API URL');
806
+ }
807
+ info("[autoconfigure] " + msg.join(', ') + " " + (msg.length > 1 ? 'are' : 'is') + " missing from the config. Autoconfiguration will run.");
808
+ case 20:
778
809
  cp = getControlPlane(envVarConfig);
779
810
  databaseName = getDatabaseName({
780
811
  config: config,
@@ -785,7 +816,7 @@ var Config = /*#__PURE__*/function () {
785
816
  url.searchParams.set('databaseName', databaseName);
786
817
  }
787
818
  info("configuring from " + url.href);
788
- _context.next = 19;
819
+ _context.next = 27;
789
820
  return fetch(url, {
790
821
  headers: {
791
822
  Authorization: "Bearer " + getInfoBearer({
@@ -795,19 +826,19 @@ var Config = /*#__PURE__*/function () {
795
826
  })["catch"](function () {
796
827
  error("Unable to auto-configure. is " + url + " available?");
797
828
  });
798
- case 19:
829
+ case 27:
799
830
  res = _context.sent;
800
831
  if (res) {
801
- _context.next = 22;
832
+ _context.next = 30;
802
833
  break;
803
834
  }
804
835
  return _context.abrupt("return", _this);
805
- case 22:
836
+ case 30:
806
837
  possibleError = res.clone();
807
- _context.prev = 23;
808
- _context.next = 26;
838
+ _context.prev = 31;
839
+ _context.next = 34;
809
840
  return res.json();
810
- case 26:
841
+ case 34:
811
842
  json = _context.sent;
812
843
  if (res.status === 404) {
813
844
  info('is the configured databaseName correct?');
@@ -819,39 +850,39 @@ var Config = /*#__PURE__*/function () {
819
850
  } else {
820
851
  database = json;
821
852
  }
822
- _context.next = 39;
853
+ _context.next = 47;
823
854
  break;
824
- case 31:
825
- _context.prev = 31;
826
- _context.t0 = _context["catch"](23);
827
- _context.next = 35;
855
+ case 39:
856
+ _context.prev = 39;
857
+ _context.t0 = _context["catch"](31);
858
+ _context.next = 43;
828
859
  return possibleError.text();
829
- case 35:
860
+ case 43:
830
861
  message = _context.sent;
831
862
  debug('Unable to auto-configure');
832
863
  error(message);
833
864
  database = {
834
865
  message: message
835
866
  };
836
- case 39:
867
+ case 47:
837
868
  info('[fetched database]', database);
838
869
  if (!(process.env.NODE_ENV !== 'TEST')) {
839
- _context.next = 49;
870
+ _context.next = 57;
840
871
  break;
841
872
  }
842
873
  if (!('message' in database)) {
843
- _context.next = 48;
874
+ _context.next = 56;
844
875
  break;
845
876
  }
846
877
  if (!('statusCode' in database)) {
847
- _context.next = 47;
878
+ _context.next = 55;
848
879
  break;
849
880
  }
850
881
  error(database);
851
882
  throw new Error('HTTP error has occurred');
852
- case 47:
883
+ case 55:
853
884
  throw new Error('Unable to auto-configure. Please remove NILEDB_NAME, NILEDB_API_URL, NILEDB_POSTGRES_URL, and/or NILEDB_HOST from your environment variables.');
854
- case 48:
885
+ case 56:
855
886
  if (typeof database === 'object') {
856
887
  _database = database, apiHost = _database.apiHost, dbHost = _database.dbHost, name = _database.name, id = _database.id;
857
888
  basePath = basePath || apiHost;
@@ -860,7 +891,7 @@ var Config = /*#__PURE__*/function () {
860
891
  dburl = new URL(dbHost);
861
892
  configuredHost = dburl.hostname;
862
893
  }
863
- case 49:
894
+ case 57:
864
895
  _this.api = new ApiConfig({
865
896
  basePath: basePath,
866
897
  cookieKey: (_config$api$cookieKey2 = config == null || (_config$api2 = config.api) == null ? void 0 : _config$api2.cookieKey) != null ? _config$api$cookieKey2 : 'token',
@@ -880,11 +911,11 @@ var Config = /*#__PURE__*/function () {
880
911
  api: _this.api
881
912
  });
882
913
  return _context.abrupt("return", _this);
883
- case 53:
914
+ case 61:
884
915
  case "end":
885
916
  return _context.stop();
886
917
  }
887
- }, _callee, null, [[23, 31]]);
918
+ }, _callee, null, [[31, 39]]);
888
919
  }));
889
920
  return function (_x) {
890
921
  return _ref2.apply(this, arguments);
@@ -1644,149 +1675,160 @@ function _fetch2() {
1644
1675
  }))["catch"](function (e) {
1645
1676
  error('[fetch][response]', {
1646
1677
  message: e.message,
1647
- stack: e.stack
1678
+ stack: e.stack,
1679
+ debug: 'Is nile-auth running?'
1648
1680
  });
1681
+ return new Error(e);
1649
1682
  });
1650
1683
  case 15:
1651
1684
  response = _context.sent;
1685
+ if (!(response instanceof Error)) {
1686
+ _context.next = 18;
1687
+ break;
1688
+ }
1689
+ return _context.abrupt("return", new ResponseError('Failed to connect to database', {
1690
+ status: 400
1691
+ }));
1692
+ case 18:
1652
1693
  if (!(response && response.status >= 200 && response.status < 300)) {
1653
- _context.next = 38;
1694
+ _context.next = 40;
1654
1695
  break;
1655
1696
  }
1656
1697
  if (!(typeof response.clone === 'function')) {
1657
- _context.next = 37;
1698
+ _context.next = 39;
1658
1699
  break;
1659
1700
  }
1660
- _context.prev = 18;
1701
+ _context.prev = 20;
1661
1702
  _context.t0 = debug;
1662
1703
  _context.t1 = "[fetch][response][" + ((_opts$method = opts == null ? void 0 : opts.method) != null ? _opts$method : 'GET') + "] " + response.status + " " + useableUrl;
1663
- _context.next = 23;
1704
+ _context.next = 25;
1664
1705
  return response.clone().json();
1665
- case 23:
1706
+ case 25:
1666
1707
  _context.t2 = _context.sent;
1667
1708
  _context.t3 = {
1668
1709
  body: _context.t2
1669
1710
  };
1670
1711
  (0, _context.t0)(_context.t1, _context.t3);
1671
- _context.next = 37;
1712
+ _context.next = 39;
1672
1713
  break;
1673
- case 28:
1674
- _context.prev = 28;
1675
- _context.t4 = _context["catch"](18);
1714
+ case 30:
1715
+ _context.prev = 30;
1716
+ _context.t4 = _context["catch"](20);
1676
1717
  _context.t5 = debug;
1677
1718
  _context.t6 = "[fetch][response][" + ((_opts$method2 = opts == null ? void 0 : opts.method) != null ? _opts$method2 : 'GET') + "] " + response.status + " " + useableUrl;
1678
- _context.next = 34;
1719
+ _context.next = 36;
1679
1720
  return response.clone().text();
1680
- case 34:
1721
+ case 36:
1681
1722
  _context.t7 = _context.sent;
1682
1723
  _context.t8 = {
1683
1724
  body: _context.t7
1684
1725
  };
1685
1726
  (0, _context.t5)(_context.t6, _context.t8);
1686
- case 37:
1727
+ case 39:
1687
1728
  return _context.abrupt("return", response);
1688
- case 38:
1729
+ case 40:
1689
1730
  if (!((response == null ? void 0 : response.status) === 404)) {
1690
- _context.next = 40;
1731
+ _context.next = 42;
1691
1732
  break;
1692
1733
  }
1693
1734
  return _context.abrupt("return", new ResponseError('Not found', {
1694
1735
  status: 404
1695
1736
  }));
1696
- case 40:
1737
+ case 42:
1697
1738
  if (!((response == null ? void 0 : response.status) === 401)) {
1698
- _context.next = 42;
1739
+ _context.next = 44;
1699
1740
  break;
1700
1741
  }
1701
1742
  return _context.abrupt("return", new ResponseError('Unauthorized', {
1702
1743
  status: 401
1703
1744
  }));
1704
- case 42:
1745
+ case 44:
1705
1746
  if (!((response == null ? void 0 : response.status) === 405)) {
1706
- _context.next = 44;
1747
+ _context.next = 46;
1707
1748
  break;
1708
1749
  }
1709
1750
  return _context.abrupt("return", new ResponseError('Method not allowed', {
1710
1751
  status: 405
1711
1752
  }));
1712
- case 44:
1753
+ case 46:
1713
1754
  errorHandler = typeof (response == null ? void 0 : response.clone) === 'function' ? response.clone() : null;
1714
1755
  msg = '';
1715
- _context.prev = 46;
1716
- _context.next = 49;
1756
+ _context.prev = 48;
1757
+ _context.next = 51;
1717
1758
  return response == null ? void 0 : response.json();
1718
- case 49:
1759
+ case 51:
1719
1760
  res = _context.sent;
1720
- _context.next = 60;
1761
+ _context.next = 63;
1721
1762
  break;
1722
- case 52:
1723
- _context.prev = 52;
1724
- _context.t9 = _context["catch"](46);
1763
+ case 54:
1764
+ _context.prev = 54;
1765
+ _context.t9 = _context["catch"](48);
1725
1766
  if (!errorHandler) {
1726
- _context.next = 59;
1767
+ _context.next = 62;
1727
1768
  break;
1728
1769
  }
1729
- _context.next = 57;
1770
+ _context.next = 59;
1730
1771
  return errorHandler.text();
1731
- case 57:
1772
+ case 59:
1732
1773
  msg = _context.sent;
1733
1774
  if (msg) {
1734
- error("[fetch][response] status: " + errorHandler.status + "]", {
1775
+ error("[fetch][response][status: " + errorHandler.status + "]", {
1735
1776
  message: msg
1736
1777
  });
1737
1778
  }
1738
- case 59:
1779
+ return _context.abrupt("return", _context.t9);
1780
+ case 62:
1739
1781
  if (!msg) {
1740
1782
  error('[fetch][response]', {
1741
1783
  e: _context.t9
1742
1784
  });
1743
1785
  }
1744
- case 60:
1786
+ case 63:
1745
1787
  if (!msg) {
1746
- _context.next = 62;
1788
+ _context.next = 65;
1747
1789
  break;
1748
1790
  }
1749
1791
  return _context.abrupt("return", new ResponseError(msg, {
1750
1792
  status: errorHandler == null ? void 0 : errorHandler.status
1751
1793
  }));
1752
- case 62:
1794
+ case 65:
1753
1795
  if (!(res && 'message' in res)) {
1754
- _context.next = 66;
1796
+ _context.next = 69;
1755
1797
  break;
1756
1798
  }
1757
1799
  _res = res, message = _res.message;
1758
- error("[fetch][response] status: " + (errorHandler == null ? void 0 : errorHandler.status) + "] " + message);
1800
+ error("[fetch][response][status: " + (errorHandler == null ? void 0 : errorHandler.status) + "] " + message);
1759
1801
  return _context.abrupt("return", new ResponseError(message, {
1760
1802
  status: 400
1761
1803
  }));
1762
- case 66:
1804
+ case 69:
1763
1805
  if (!(res && 'errors' in res)) {
1764
- _context.next = 70;
1806
+ _context.next = 73;
1765
1807
  break;
1766
1808
  }
1767
1809
  _res2 = res, _res2$errors = _res2.errors, _message = _res2$errors[0];
1768
- error("[fetch][response] status: " + (errorHandler == null ? void 0 : errorHandler.status) + "] " + _message);
1810
+ error("[fetch][response] [status: " + (errorHandler == null ? void 0 : errorHandler.status) + "] " + _message);
1769
1811
  return _context.abrupt("return", new ResponseError(_message, {
1770
1812
  status: 400
1771
1813
  }));
1772
- case 70:
1773
- error("[fetch][response] status: " + (errorHandler == null ? void 0 : errorHandler.status) + "] UNHANDLED ERROR", {
1814
+ case 73:
1815
+ error("[fetch][response][status: " + (errorHandler == null ? void 0 : errorHandler.status) + "] UNHANDLED ERROR", {
1774
1816
  res: res
1775
1817
  });
1776
1818
  return _context.abrupt("return", new ResponseError(null, {
1777
1819
  status: (_response$status = response == null ? void 0 : response.status) != null ? _response$status : 500
1778
1820
  }));
1779
- case 74:
1780
- _context.prev = 74;
1821
+ case 77:
1822
+ _context.prev = 77;
1781
1823
  _context.t10 = _context["catch"](12);
1782
1824
  return _context.abrupt("return", new ResponseError('an unexpected error has occurred', {
1783
1825
  status: 500
1784
1826
  }));
1785
- case 77:
1827
+ case 80:
1786
1828
  case "end":
1787
1829
  return _context.stop();
1788
1830
  }
1789
- }, _callee, null, [[12, 74], [18, 28], [46, 52]]);
1831
+ }, _callee, null, [[12, 77], [20, 30], [48, 54]]);
1790
1832
  }));
1791
1833
  return _fetch2.apply(this, arguments);
1792
1834
  }