@k-int/stripes-kint-components 2.8.1 → 2.8.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.8.2 2022-07-25
2
+ * New util function `parseErrorResponse`, used in places where we catch http errors, allows for text only response bodies
3
+
1
4
  ## 2.8.1 2022-07-21
2
5
  * ActionList previously added actionListItems directly to cached object--sometimes this caused the react-query cache ITSELF to update, although I'm not sure why here and not anywhere else. Fixed by creating a clone internally in ActionListFieldArray and assigning actionListActions on that.
3
6
 
package/es/index.js CHANGED
@@ -264,6 +264,12 @@ Object.defineProperty(exports, "matchString", {
264
264
  return _utils.matchString;
265
265
  }
266
266
  });
267
+ Object.defineProperty(exports, "parseErrorResponse", {
268
+ enumerable: true,
269
+ get: function get() {
270
+ return _utils.parseErrorResponse;
271
+ }
272
+ });
267
273
  Object.defineProperty(exports, "refdataOptions", {
268
274
  enumerable: true,
269
275
  get: function get() {
@@ -31,6 +31,8 @@ var _CustomPropertyForm = _interopRequireDefault(require("./CustomPropertyForm")
31
31
 
32
32
  var _hooks = require("../../hooks");
33
33
 
34
+ var _utils = require("../../utils");
35
+
34
36
  var _jsxRuntime = require("react/jsx-runtime");
35
37
 
36
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -162,7 +164,7 @@ var CustomPropertiesSettings = function CustomPropertiesSettings(_ref) {
162
164
  switch (_context.prev = _context.next) {
163
165
  case 0:
164
166
  _context.next = 2;
165
- return err.response.json();
167
+ return (0, _utils.parseErrorResponse)(err.response);
166
168
 
167
169
  case 2:
168
170
  errorResp = _context.sent;
@@ -23,6 +23,8 @@ var _ActionList = _interopRequireDefault(require("../ActionList"));
23
23
 
24
24
  var _validators = require("../utils/validators");
25
25
 
26
+ var _utils = require("../utils");
27
+
26
28
  var _jsxRuntime = require("react/jsx-runtime");
27
29
 
28
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -136,7 +138,7 @@ var EditableRefdataCategoryList = function EditableRefdataCategoryList(_ref) {
136
138
  switch (_context.prev = _context.next) {
137
139
  case 0:
138
140
  _context.next = 2;
139
- return err.response.json();
141
+ return (0, _utils.parseErrorResponse)(err.response);
140
142
 
141
143
  case 2:
142
144
  errorResp = _context.sent;
@@ -23,6 +23,8 @@ var _ActionList = _interopRequireDefault(require("../ActionList"));
23
23
 
24
24
  var _validators = require("../utils/validators");
25
25
 
26
+ var _utils = require("../utils");
27
+
26
28
  var _jsxRuntime = require("react/jsx-runtime");
27
29
 
28
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -149,7 +151,7 @@ var EditableRefdataList = function EditableRefdataList(_ref) {
149
151
  switch (_context.prev = _context.next) {
150
152
  case 0:
151
153
  _context.next = 2;
152
- return err.response.json();
154
+ return (0, _utils.parseErrorResponse)(err.response);
153
155
 
154
156
  case 2:
155
157
  errorResp = _context.sent;
@@ -45,6 +45,12 @@ Object.defineProperty(exports, "matchString", {
45
45
  return _matchString.default;
46
46
  }
47
47
  });
48
+ Object.defineProperty(exports, "parseErrorResponse", {
49
+ enumerable: true,
50
+ get: function get() {
51
+ return _parseErrorResponse.default;
52
+ }
53
+ });
48
54
  Object.defineProperty(exports, "refdataOptions", {
49
55
  enumerable: true,
50
56
  get: function get() {
@@ -114,4 +120,6 @@ var _matchString = _interopRequireDefault(require("./matchString"));
114
120
 
115
121
  var _highlightString = require("./highlightString");
116
122
 
123
+ var _parseErrorResponse = _interopRequireDefault(require("./parseErrorResponse"));
124
+
117
125
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
11
+
12
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
13
+
14
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
+
16
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
+
18
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
19
+
20
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
21
+
22
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
23
+
24
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
25
+
26
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
27
+
28
+ var parseErrorResponse = /*#__PURE__*/function () {
29
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(responseObj) {
30
+ var _ref2, _ref2$find;
31
+
32
+ var errorResp, contentType;
33
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
34
+ while (1) {
35
+ switch (_context.prev = _context.next) {
36
+ case 0:
37
+ contentType = (_ref2 = _toConsumableArray(responseObj === null || responseObj === void 0 ? void 0 : responseObj.headers)) === null || _ref2 === void 0 ? void 0 : (_ref2$find = _ref2.find(function (header) {
38
+ return header[0] === 'content-type';
39
+ })) === null || _ref2$find === void 0 ? void 0 : _ref2$find[1];
40
+
41
+ if (!contentType.includes('json')) {
42
+ _context.next = 7;
43
+ break;
44
+ }
45
+
46
+ _context.next = 4;
47
+ return responseObj.json();
48
+
49
+ case 4:
50
+ errorResp = _context.sent;
51
+ _context.next = 17;
52
+ break;
53
+
54
+ case 7:
55
+ _context.prev = 7;
56
+ _context.next = 10;
57
+ return responseObj.text();
58
+
59
+ case 10:
60
+ _context.t0 = _context.sent;
61
+ errorResp = {
62
+ message: _context.t0
63
+ };
64
+ _context.next = 17;
65
+ break;
66
+
67
+ case 14:
68
+ _context.prev = 14;
69
+ _context.t1 = _context["catch"](7);
70
+ errorResp = {
71
+ message: "something went wrong"
72
+ };
73
+
74
+ case 17:
75
+ return _context.abrupt("return", errorResp);
76
+
77
+ case 18:
78
+ case "end":
79
+ return _context.stop();
80
+ }
81
+ }
82
+ }, _callee, null, [[7, 14]]);
83
+ }));
84
+
85
+ return function parseErrorResponse(_x) {
86
+ return _ref.apply(this, arguments);
87
+ };
88
+ }();
89
+
90
+ var _default = parseErrorResponse;
91
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k-int/stripes-kint-components",
3
- "version": "2.8.1",
3
+ "version": "2.8.2",
4
4
  "description": "Stripes Component library for K-Int specific applications",
5
5
  "sideEffects": [
6
6
  "*.css"
package/src/index.js CHANGED
@@ -29,6 +29,7 @@ export {
29
29
  refdataQueryKey,
30
30
  selectorSafe,
31
31
  typedownQueryKey,
32
+ parseErrorResponse,
32
33
  } from './lib/utils';
33
34
 
34
35
  // Validators (Some/all copied from stripes-erm-components but this gives another way to acquire them)
@@ -15,6 +15,7 @@ import CustomPropertiesLookup from './CustomPropertiesLookup';
15
15
  import CustomPropertyView from './CustomPropertyView';
16
16
  import CustomPropertiesForm from './CustomPropertyForm';
17
17
  import { useMutateCustomProperties, useRefdata } from '../../hooks';
18
+ import { parseErrorResponse } from '../../utils';
18
19
 
19
20
  const EDITING = 'edit';
20
21
  const CREATING = 'create';
@@ -99,7 +100,8 @@ const CustomPropertiesSettings = ({
99
100
  // Default delete behaviour is to fire a callout, either with kint-components default message
100
101
  // or one provided in labelOverrides, which is passed the error message and customProperty in question
101
102
  delete: async (err) => {
102
- const errorResp = await err.response.json();
103
+ const errorResp = await parseErrorResponse(err.response);
104
+
103
105
  callout.sendCallout({
104
106
  message: labelOverrides?.deleteError ? labelOverrides.deleteError(errorResp?.message, customProperty) : (
105
107
  <FormattedMessage
@@ -9,6 +9,7 @@ import { useMutateRefdataCategory, useRefdata } from '../hooks';
9
9
 
10
10
  import ActionList from '../ActionList';
11
11
  import { required } from '../utils/validators';
12
+ import { parseErrorResponse } from '../utils';
12
13
 
13
14
  const propTypes = {
14
15
  afterQueryCalls: PropTypes.object,
@@ -70,7 +71,7 @@ const EditableRefdataCategoryList = ({
70
71
  // Default delete behaviour is to fire a callout, either with kint-components default message
71
72
  // or one provided in labelOverrides, which is passed the error message and refdata in question
72
73
  delete: async (err) => {
73
- const errorResp = await err.response.json();
74
+ const errorResp = await parseErrorResponse(err.response);
74
75
  callout.sendCallout({
75
76
  message: labelOverrides?.deleteError ? labelOverrides.deleteError(errorResp?.message, deleteModal?.refdata) : (
76
77
  <FormattedMessage
@@ -9,6 +9,7 @@ import { useMutateRefdataValue, useRefdata } from '../hooks';
9
9
 
10
10
  import ActionList from '../ActionList';
11
11
  import { required } from '../utils/validators';
12
+ import { parseErrorResponse } from '../utils';
12
13
 
13
14
  const propTypes = {
14
15
  afterQueryCalls: PropTypes.object,
@@ -75,7 +76,7 @@ const EditableRefdataList = ({
75
76
  // Default delete behaviour is to fire a callout, either with kint-components default message
76
77
  // or one provided in labelOverrides, which is passed the error message and refdata in question
77
78
  delete: async (err) => {
78
- const errorResp = await err.response.json();
79
+ const errorResp = await parseErrorResponse(err.response);
79
80
  callout.sendCallout({
80
81
  message: labelOverrides?.deleteError ? labelOverrides.deleteError(errorResp?.message, deleteModal?.refdata) : (
81
82
  <FormattedMessage
@@ -19,3 +19,6 @@ export { default as toCamelCase } from './toCamelCase'; // I hate that this exis
19
19
 
20
20
  export { default as matchString } from './matchString';
21
21
  export { boldString, highlightString } from './highlightString';
22
+
23
+ // HTTP Utils
24
+ export { default as parseErrorResponse } from './parseErrorResponse';
@@ -0,0 +1,18 @@
1
+ const parseErrorResponse = async (responseObj) => {
2
+ let errorResp;
3
+ const contentType = [...responseObj?.headers]?.find(header => header[0] === 'content-type')?.[1];
4
+
5
+ if (contentType.includes('json')) {
6
+ errorResp = await responseObj.json();
7
+ } else {
8
+ try {
9
+ errorResp = { message: await responseObj.text() };
10
+ } catch {
11
+ errorResp = { message: "something went wrong" };
12
+ }
13
+ }
14
+
15
+ return errorResp;
16
+ };
17
+
18
+ export default parseErrorResponse;