@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.
@@ -467,7 +467,7 @@ function Logger(config) {
467
467
 
468
468
  var getSecureCookies = function getSecureCookies(cfg) {
469
469
  var config = cfg.config;
470
- if (process.env.NILEDB_SECURECOOKIES) {
470
+ if (stringCheck(process.env.NILEDB_SECURECOOKIES)) {
471
471
  return Boolean(process.env.NILEDB_SECURECOOKIES);
472
472
  }
473
473
  return config == null ? void 0 : config.secureCookies;
@@ -477,19 +477,20 @@ var getDatabaseId = function getDatabaseId(cfg) {
477
477
  logger = cfg.logger;
478
478
  var _Logger = Logger(config, '[databaseId]'),
479
479
  info = _Logger.info;
480
- if (config != null && config.databaseId) {
481
- logger && info(logger + "[config] " + config.databaseId);
480
+ if (stringCheck(config == null ? void 0 : config.databaseId)) {
481
+ logger && info(logger + "[config] " + (config == null ? void 0 : config.databaseId));
482
482
  return String(config == null ? void 0 : config.databaseId);
483
483
  }
484
- if (process.env.NILEDB_POSTGRES_URL) {
484
+ var dbId = stringCheck(process.env.NILEDB_API_URL);
485
+ if (dbId) {
485
486
  try {
486
- var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
487
- return pgUrl.pathname.substring(1);
487
+ var pgUrl = new URL(dbId);
488
+ return pgUrl.pathname.split('/')[3];
488
489
  } catch (e) {
489
490
  // ok to fail
490
491
  }
491
492
  }
492
- logger && info(logger + "[NILEDB_ID] " + process.env.NILEDB_ID);
493
+ logger && info(logger + "[NILEDB_ID] " + String(process.env.NILEDB_ID));
493
494
  return process.env.NILEDB_ID;
494
495
  };
495
496
  var getUsername = function getUsername(cfg) {
@@ -501,13 +502,14 @@ var getUsername = function getUsername(cfg) {
501
502
  logger && info(logger + "[config] " + config.user);
502
503
  return String(config == null ? void 0 : config.user);
503
504
  }
504
- if (process.env.NILEDB_POSTGRES_URL) {
505
- var url = new URL(process.env.NILEDB_POSTGRES_URL);
505
+ var pg = stringCheck(process.env.NILEDB_POSTGRES_URL);
506
+ if (pg) {
507
+ var url = new URL(pg);
506
508
  if (url.username) {
507
509
  return url.username;
508
510
  }
509
511
  }
510
- logger && info(logger + "[NILEDB_USER] " + process.env.NILEDB_USER);
512
+ logger && info(logger + "[NILEDB_USER] " + String(process.env.NILEDB_USER));
511
513
  return process.env.NILEDB_USER;
512
514
  };
513
515
  var getPassword = function getPassword(cfg) {
@@ -516,17 +518,18 @@ var getPassword = function getPassword(cfg) {
516
518
  var log = logProtector(logger);
517
519
  var _Logger3 = Logger(config, '[password]'),
518
520
  info = _Logger3.info;
519
- if (config != null && config.password) {
520
- log && info(logger + "[config] " + config.password);
521
- return String(config.password);
521
+ if (stringCheck(config == null ? void 0 : config.password)) {
522
+ log && info(logger + "[config] " + (config == null ? void 0 : config.password));
523
+ return String(config == null ? void 0 : config.password);
522
524
  }
523
- if (process.env.NILEDB_POSTGRES_URL) {
524
- var url = new URL(process.env.NILEDB_POSTGRES_URL);
525
+ var pg = stringCheck(process.env.NILEDB_POSTGRES_URL);
526
+ if (pg) {
527
+ var url = new URL(pg);
525
528
  if (url.password) {
526
529
  return url.password;
527
530
  }
528
531
  }
529
- logger && info(logger + "[NILEDB_PASSWORD] " + process.env.NILEDB_PASSWORD);
532
+ logger && info(logger + "[NILEDB_PASSWORD] " + String(process.env.NILEDB_PASSWORD));
530
533
  return process.env.NILEDB_PASSWORD;
531
534
  };
532
535
  var getInfoBearer = function getInfoBearer(cfg) {
@@ -538,12 +541,13 @@ var getToken = function getToken(cfg) {
538
541
  logger = cfg.logger;
539
542
  var _Logger4 = Logger(config, '[token]'),
540
543
  info = _Logger4.info;
541
- if (config != null && (_config$api = config.api) != null && _config$api.token) {
544
+ if (stringCheck(config == null || (_config$api = config.api) == null ? void 0 : _config$api.token)) {
542
545
  var _config$api2, _config$api3;
543
- logger && info(logger + "[config] " + ((_config$api2 = config.api) == null ? void 0 : _config$api2.token));
544
- return String((_config$api3 = config.api) == null ? void 0 : _config$api3.token);
546
+ logger && info(logger + "[config] " + (config == null || (_config$api2 = config.api) == null ? void 0 : _config$api2.token));
547
+ return String(config == null || (_config$api3 = config.api) == null ? void 0 : _config$api3.token);
545
548
  }
546
- if (process.env.NILEDB_TOKEN) {
549
+ var token = stringCheck(process.env.NILEDB_TOKEN);
550
+ if (token) {
547
551
  logger && info(logger + "[NILEDB_TOKEN] " + process.env.NILEDB_TOKEN);
548
552
  return process.env.NILEDB_TOKEN;
549
553
  }
@@ -554,11 +558,12 @@ var getDatabaseName = function getDatabaseName(cfg) {
554
558
  logger = cfg.logger;
555
559
  var _Logger5 = Logger(config, '[databaseName]'),
556
560
  info = _Logger5.info;
557
- if (config != null && config.databaseName) {
558
- logger && info(logger + "[config] " + config.databaseName);
559
- return String(config.databaseName);
561
+ if (stringCheck(config == null ? void 0 : config.databaseName)) {
562
+ logger && info(logger + "[config] " + (config == null ? void 0 : config.databaseName));
563
+ return String(config == null ? void 0 : config.databaseName);
560
564
  }
561
- if (process.env.NILEDB_NAME) {
565
+ var name = stringCheck(process.env.NILEDB_NAME);
566
+ if (name) {
562
567
  logger && info(logger + "[NILEDB_NAME] " + process.env.NILEDB_NAME);
563
568
  return process.env.NILEDB_NAME;
564
569
  }
@@ -577,13 +582,13 @@ var getTenantId = function getTenantId(cfg) {
577
582
  logger = cfg.logger;
578
583
  var _Logger6 = Logger(config, '[tenantId]'),
579
584
  info = _Logger6.info;
580
- if (config != null && config.tenantId) {
581
- logger && info(logger + "[config] " + config.tenantId);
582
- return config.tenantId;
585
+ if (stringCheck(config == null ? void 0 : config.tenantId)) {
586
+ logger && info(logger + "[config] " + (config == null ? void 0 : config.tenantId));
587
+ return String(config == null ? void 0 : config.tenantId);
583
588
  }
584
- if (process.env.NILEDB_TENANT) {
589
+ if (stringCheck(process.env.NILEDB_TENANT)) {
585
590
  logger && info(logger + "[NILEDB_TENANT] " + process.env.NILEDB_TENANT);
586
- return process.env.NILEDB_TENANT;
591
+ return String(process.env.NILEDB_TENANT);
587
592
  }
588
593
  return null;
589
594
  };
@@ -600,14 +605,15 @@ var getBasePath = function getBasePath(cfg) {
600
605
  info = _Logger7.info,
601
606
  error = _Logger7.error;
602
607
  var basePath = config == null || (_config$api4 = config.api) == null ? void 0 : _config$api4.basePath;
603
- if (basePath) {
608
+ if (stringCheck(basePath)) {
604
609
  logger && info(logger + "[config] " + basePath);
605
610
  return basePath;
606
611
  }
607
- if (process.env.NILEDB_API_URL) {
612
+ var envUrl = stringCheck(process.env.NILEDB_API_URL);
613
+ if (envUrl) {
608
614
  logger && info(logger + "[NILEDB_API_URL] " + process.env.NILEDB_API_URL);
609
615
  try {
610
- var apiUrl = new URL(process.env.NILEDB_API_URL);
616
+ var apiUrl = new URL(envUrl);
611
617
  return apiUrl.href;
612
618
  } catch (e) {
613
619
  if (e instanceof Error) {
@@ -623,14 +629,15 @@ var getControlPlane = function getControlPlane(cfg) {
623
629
  logger = cfg.logger;
624
630
  var _Logger8 = Logger(config, '[basePath]'),
625
631
  info = _Logger8.info;
626
- if (config != null && config.configureUrl) {
627
- logger && info(logger + "[config] " + config.configureUrl);
628
- return config.configureUrl;
632
+ if (stringCheck(config == null ? void 0 : config.configureUrl)) {
633
+ logger && info(logger + "[config] " + (config == null ? void 0 : config.configureUrl));
634
+ return String(config == null ? void 0 : config.configureUrl);
629
635
  }
630
- if (process.env.NILEDB_CONFIGURE) {
636
+ var autoConfigUrl = stringCheck(process.env.NILEDB_CONFIGURE);
637
+ if (autoConfigUrl) {
631
638
  logger && info(logger + "[NILEDB_CONFIGURE] " + process.env.NILEDB_CONFIGURE);
632
639
  // backwards compatible, but not really
633
- if (!process.env.NILEDB_CONFIGURE.startsWith('http')) {
640
+ if (!autoConfigUrl.startsWith('http')) {
634
641
  return "https://" + process.env.NILEDB_CONFIGURE;
635
642
  }
636
643
  return process.env.NILEDB_CONFIGURE;
@@ -643,20 +650,22 @@ function getDbHost(cfg) {
643
650
  logger = cfg.logger;
644
651
  var _Logger9 = Logger(config, '[db.host]'),
645
652
  info = _Logger9.info;
646
- if (config != null && config.db && config.db.host) {
647
- logger && info(logger + "[config] " + (config == null ? void 0 : config.db.host));
648
- return config.db.host;
653
+ if (stringCheck((config == null ? void 0 : config.db) && config.db.host)) {
654
+ var _config$db, _config$db2;
655
+ logger && info(logger + "[config] " + (config == null || (_config$db = config.db) == null ? void 0 : _config$db.host));
656
+ return String(config == null || (_config$db2 = config.db) == null ? void 0 : _config$db2.host);
649
657
  }
650
- if (process.env.NILEDB_POSTGRES_URL) {
658
+ var pg = stringCheck(process.env.NILEDB_POSTGRES_URL);
659
+ if (pg) {
651
660
  try {
652
- var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
661
+ var pgUrl = new URL(pg);
653
662
  logger && info(logger + "[NILEDB_POSTGRES_URL] " + pgUrl.hostname);
654
663
  return pgUrl.hostname;
655
664
  } catch (e) {
656
665
  // ok to fail
657
666
  }
658
667
  }
659
- if (process.env.NILEDB_HOST) {
668
+ if (stringCheck(process.env.NILEDB_HOST)) {
660
669
  logger && info(logger + "[NILEDB_HOST] " + process.env.NILEDB_HOST);
661
670
  return process.env.NILEDB_HOST;
662
671
  }
@@ -664,23 +673,24 @@ function getDbHost(cfg) {
664
673
  return 'db.thenile.dev';
665
674
  }
666
675
  function getDbPort(cfg) {
667
- var _config$db;
676
+ var _config$db3;
668
677
  var config = cfg.config,
669
678
  logger = cfg.logger;
670
679
  var _Logger10 = Logger(config, '[db.port]'),
671
680
  info = _Logger10.info;
672
- if (config != null && (_config$db = config.db) != null && _config$db.port && config.db.port != null) {
673
- var _config$db2;
681
+ if (config != null && (_config$db3 = config.db) != null && _config$db3.port && config.db.port != null) {
682
+ var _config$db4;
674
683
  logger && info(logger + "[config] " + (config == null ? void 0 : config.db.port));
675
- return Number((_config$db2 = config.db) == null ? void 0 : _config$db2.port);
684
+ return Number((_config$db4 = config.db) == null ? void 0 : _config$db4.port);
676
685
  }
677
- if (process.env.NILEDB_PORT) {
686
+ if (stringCheck(process.env.NILEDB_PORT)) {
678
687
  logger && info(logger + "[NILEDB_PORT] " + process.env.NILEDB_PORT);
679
688
  return Number(process.env.NILEDB_PORT);
680
689
  }
681
- if (process.env.NILEDB_POSTGRES_URL) {
690
+ var pg = stringCheck(process.env.NILEDB_POSTGRES_URL);
691
+ if (pg) {
682
692
  try {
683
- var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
693
+ var pgUrl = new URL(pg);
684
694
  if (pgUrl.port) {
685
695
  return Number(pgUrl.port);
686
696
  }
@@ -695,6 +705,12 @@ function getDbPort(cfg) {
695
705
  var logProtector = function logProtector(logger) {
696
706
  return logger ;
697
707
  };
708
+ var stringCheck = function stringCheck(str) {
709
+ if (str && str !== '') {
710
+ return str;
711
+ }
712
+ return;
713
+ };
698
714
 
699
715
  var _excluded$2 = ["host", "port"],
700
716
  _excluded2 = ["host", "port"];
@@ -742,7 +758,7 @@ var Config = /*#__PURE__*/function () {
742
758
  this.configure = /*#__PURE__*/function () {
743
759
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
744
760
  var _config$db, _config$api$cookieKey2, _config$api2;
745
- 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;
761
+ 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;
746
762
  return _regeneratorRuntime().wrap(function _callee$(_context) {
747
763
  while (1) switch (_context.prev = _context.next) {
748
764
  case 0:
@@ -755,7 +771,7 @@ var Config = /*#__PURE__*/function () {
755
771
  configuredPort = port != null ? port : getDbPort(envVarConfig);
756
772
  basePath = getBasePath(envVarConfig);
757
773
  if (!(configuredHost && _this.databaseName && _this.databaseId && basePath)) {
758
- _context.next = 12;
774
+ _context.next = 14;
759
775
  break;
760
776
  }
761
777
  info('Already configured, aborting fetch');
@@ -778,7 +794,22 @@ var Config = /*#__PURE__*/function () {
778
794
  api: _this.api
779
795
  });
780
796
  return _context.abrupt("return", _this);
781
- case 12:
797
+ case 14:
798
+ msg = [];
799
+ if (!configuredHost) {
800
+ msg.push('Database host');
801
+ }
802
+ if (!_this.databaseName) {
803
+ msg.push('Database name');
804
+ }
805
+ if (!_this.databaseId) {
806
+ msg.push('Database id');
807
+ }
808
+ if (!basePath) {
809
+ msg.push('API URL');
810
+ }
811
+ info("[autoconfigure] " + msg.join(', ') + " " + (msg.length > 1 ? 'are' : 'is') + " missing from the config. Autoconfiguration will run.");
812
+ case 20:
782
813
  cp = getControlPlane(envVarConfig);
783
814
  databaseName = getDatabaseName({
784
815
  config: config,
@@ -789,7 +820,7 @@ var Config = /*#__PURE__*/function () {
789
820
  url.searchParams.set('databaseName', databaseName);
790
821
  }
791
822
  info("configuring from " + url.href);
792
- _context.next = 19;
823
+ _context.next = 27;
793
824
  return fetch(url, {
794
825
  headers: {
795
826
  Authorization: "Bearer " + getInfoBearer({
@@ -799,19 +830,19 @@ var Config = /*#__PURE__*/function () {
799
830
  })["catch"](function () {
800
831
  error("Unable to auto-configure. is " + url + " available?");
801
832
  });
802
- case 19:
833
+ case 27:
803
834
  res = _context.sent;
804
835
  if (res) {
805
- _context.next = 22;
836
+ _context.next = 30;
806
837
  break;
807
838
  }
808
839
  return _context.abrupt("return", _this);
809
- case 22:
840
+ case 30:
810
841
  possibleError = res.clone();
811
- _context.prev = 23;
812
- _context.next = 26;
842
+ _context.prev = 31;
843
+ _context.next = 34;
813
844
  return res.json();
814
- case 26:
845
+ case 34:
815
846
  json = _context.sent;
816
847
  if (res.status === 404) {
817
848
  info('is the configured databaseName correct?');
@@ -823,35 +854,35 @@ var Config = /*#__PURE__*/function () {
823
854
  } else {
824
855
  database = json;
825
856
  }
826
- _context.next = 39;
857
+ _context.next = 47;
827
858
  break;
828
- case 31:
829
- _context.prev = 31;
830
- _context.t0 = _context["catch"](23);
831
- _context.next = 35;
859
+ case 39:
860
+ _context.prev = 39;
861
+ _context.t0 = _context["catch"](31);
862
+ _context.next = 43;
832
863
  return possibleError.text();
833
- case 35:
864
+ case 43:
834
865
  message = _context.sent;
835
866
  debug('Unable to auto-configure');
836
867
  error(message);
837
868
  database = {
838
869
  message: message
839
870
  };
840
- case 39:
871
+ case 47:
841
872
  info('[fetched database]', database);
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
  }