@ancon/wildcat-utils 1.35.0 → 1.36.1

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.
@@ -1 +1 @@
1
- "use strict";function i(t){return t instanceof Error||typeof t=="object"&&!!(t!=null&&t.message)}function f(t){return typeof(t==null?void 0:t.message)=="string"}function c(t,o,e){if(i(t)){const s=t;return o&&(s.code=o),e&&(s.additionalData=e),s}const n=new Error("Unknown error");return f(t)?(t.message&&(n.message=t.message),n):(typeof t=="string"&&(n.message=t,o&&(n.code=o)),n)}module.exports=c;
1
+ "use strict";function f(s){return s instanceof Error||typeof s=="object"&&!!(s!=null&&s.message)}function i(s){return typeof(s==null?void 0:s.message)=="string"}function c(s,o,t){if(f(s)){const e=s;return o&&(e.code=o),t&&(e.additionalData=t),e}const n=new Error("Unknown error");return t&&(n.additionalData=t),i(s)?(s.message&&(n.message=s.message),n):(typeof s=="string"&&(n.message=s,o&&(n.code=o)),n)}module.exports=c;
@@ -4,14 +4,14 @@ function f(n) {
4
4
  function i(n) {
5
5
  return typeof (n == null ? void 0 : n.message) == "string";
6
6
  }
7
- function a(n, t, e) {
7
+ function c(n, s, t) {
8
8
  if (f(n)) {
9
- const s = n;
10
- return t && (s.code = t), e && (s.additionalData = e), s;
9
+ const e = n;
10
+ return s && (e.code = s), t && (e.additionalData = t), e;
11
11
  }
12
12
  const o = new Error("Unknown error");
13
- return i(n) ? (n.message && (o.message = n.message), o) : (typeof n == "string" && (o.message = n, t && (o.code = t)), o);
13
+ return t && (o.additionalData = t), i(n) ? (n.message && (o.message = n.message), o) : (typeof n == "string" && (o.message = n, s && (o.code = s)), o);
14
14
  }
15
15
  export {
16
- a as default
16
+ c as default
17
17
  };
@@ -1,3 +1,6 @@
1
- import { APIError, APIGenericError } from '@ancon/wildcat-types';
1
+ import { APIError, APIGenericError, ErrorCode } from '@ancon/wildcat-types';
2
+ /** Whether provided error is an API error */
2
3
  declare function isAPIError<AdditionalDataType = unknown, ErrorType = APIGenericError<AdditionalDataType>>(error: unknown): error is APIError<AdditionalDataType, ErrorType>;
4
+ /** Whether provided error is an API error with the provided `errorCode` */
5
+ declare function isAPIError<AdditionalDataType = unknown, ErrorType = APIGenericError<AdditionalDataType>>(error: unknown, errorCode: ErrorCode): error is APIError<AdditionalDataType, ErrorType>;
3
6
  export default isAPIError;
@@ -1 +1 @@
1
- "use strict";const t=require("@ancon/wildcat-types"),i=require("axios");function n(e){var r,s;const o=Object.values(t.ErrorCode);return i.isAxiosError(e)&&typeof((s=(r=e.response)==null?void 0:r.data)==null?void 0:s.errorCode)=="string"&&o.includes(e.response.data.errorCode)}module.exports=n;
1
+ "use strict";const a=require("@ancon/wildcat-types"),u=require("axios");function n(e,s){var r,t,o;const i=Object.values(a.ErrorCode);return s!=null?n(e)&&((r=e.response)==null?void 0:r.data.errorCode)===s:u.isAxiosError(e)&&typeof((o=(t=e.response)==null?void 0:t.data)==null?void 0:o.errorCode)=="string"&&i.includes(e.response.data.errorCode)}module.exports=n;
@@ -1,9 +1,9 @@
1
- import { ErrorCode as t } from "@ancon/wildcat-types";
2
- import { isAxiosError as a } from "axios";
3
- function d(r) {
4
- var o, e;
5
- const s = Object.values(t);
6
- return a(r) && typeof ((e = (o = r.response) == null ? void 0 : o.data) == null ? void 0 : e.errorCode) == "string" && s.includes(r.response.data.errorCode);
1
+ import { ErrorCode as a } from "@ancon/wildcat-types";
2
+ import { isAxiosError as i } from "axios";
3
+ function d(e, o) {
4
+ var r, s, t;
5
+ const n = Object.values(a);
6
+ return o != null ? d(e) && ((r = e.response) == null ? void 0 : r.data.errorCode) === o : i(e) && typeof ((t = (s = e.response) == null ? void 0 : s.data) == null ? void 0 : t.errorCode) == "string" && n.includes(e.response.data.errorCode);
7
7
  }
8
8
  export {
9
9
  d as default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.35.0",
3
+ "version": "1.36.1",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",