@kwiz/node 1.0.14 → 1.0.15
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/dist/axios.d.ts +5 -1
- package/dist/axios.js +14 -1
- package/dist/axios.js.map +1 -1
- package/package.json +1 -1
- package/src/axios.ts +14 -1
package/dist/axios.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from "axios";
|
|
1
|
+
import { AxiosError, AxiosRequestConfig } from "axios";
|
|
2
2
|
type axiosConfigOptions = {
|
|
3
3
|
contantType?: "application/json" | "application/json; odata=nometadata" | "application/xml";
|
|
4
4
|
};
|
|
5
5
|
export declare function getAxiosConfigBearer(token: string, options?: axiosConfigOptions): AxiosRequestConfig<any>;
|
|
6
6
|
export declare function getAxiosConfig(token?: string, options?: axiosConfigOptions): AxiosRequestConfig<any>;
|
|
7
|
+
export declare function getAxiosErrorData(error: AxiosError): {
|
|
8
|
+
code: string;
|
|
9
|
+
message: string;
|
|
10
|
+
};
|
|
7
11
|
export {};
|
package/dist/axios.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAxiosConfig = exports.getAxiosConfigBearer = void 0;
|
|
3
|
+
exports.getAxiosErrorData = exports.getAxiosConfig = exports.getAxiosConfigBearer = void 0;
|
|
4
4
|
const common_1 = require("@kwiz/common");
|
|
5
5
|
const https_1 = require("https");
|
|
6
6
|
function getAxiosConfigBearer(token, options) {
|
|
@@ -27,4 +27,17 @@ function getAxiosConfig(token, options) {
|
|
|
27
27
|
return config;
|
|
28
28
|
}
|
|
29
29
|
exports.getAxiosConfig = getAxiosConfig;
|
|
30
|
+
function getAxiosErrorData(error) {
|
|
31
|
+
let code = error.code || "Unknown";
|
|
32
|
+
let errorMessage = error.message || "Unspecified error";
|
|
33
|
+
if (error && error.response && error.response.data && error.response.data["odata.error"]) {
|
|
34
|
+
let errorData = error.response.data["odata.error"];
|
|
35
|
+
if (errorData.message && errorData.message.value)
|
|
36
|
+
errorMessage = errorData.message.value;
|
|
37
|
+
if (errorData && errorData.code)
|
|
38
|
+
code = errorData.code;
|
|
39
|
+
}
|
|
40
|
+
return { code: code, message: errorMessage };
|
|
41
|
+
}
|
|
42
|
+
exports.getAxiosErrorData = getAxiosErrorData;
|
|
30
43
|
//# sourceMappingURL=axios.js.map
|
package/dist/axios.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios.js","sourceRoot":"","sources":["../src/axios.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AAEnD,iCAA2C;AAK3C,SAAgB,oBAAoB,CAAC,KAAa,EAAE,OAA4B;IAC5E,OAAO,cAAc,CAAC,UAAU,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC;AAFD,oDAEC;AAED,SAAgB,cAAc,CAAC,KAAc,EAAE,OAA4B;IACvE,kCAAkC;IAClC,mBAAW,CAAC,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC;IAC/C,MAAM,MAAM,GAA4B;QACpC,SAAS,EAAE,IAAI,aAAK,CAAC;YACjB,kBAAkB,EAAE,KAAK;SAC5B,CAAC;QACF,OAAO,EAAE,EAAE;KACd,CAAC;IAEF,IAAI,CAAC,IAAA,4BAAmB,EAAC,KAAK,CAAC;QAC3B,MAAM,CAAC,OAAQ,CAAC,aAAa,GAAG,KAAK,CAAC;IAE1C,IAAI,OAAO,EAAE,CAAC;QACV,IAAI,CAAC,IAAA,4BAAmB,EAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YAC5C,MAAM,CAAC,OAAQ,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;YACtD,MAAM,CAAC,OAAQ,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;QACpD,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CA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AAI,CAAC,aAAa,CAAC,EAAE,CAAC;QACvF,IAAI,SAAS,GAAmD,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACnG,IAAI,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,KAAK;YAC5C,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC;QAC3C,IAAI,SAAS,IAAI,SAAS,CAAC,IAAI;YAC3B,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;IAC9B,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;AACjD,CAAC;AAXD,8CAWC"}
|
package/package.json
CHANGED
package/src/axios.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isNullOrEmptyString } from "@kwiz/common";
|
|
2
|
-
import { AxiosRequestConfig } from "axios";
|
|
2
|
+
import { AxiosError, AxiosRequestConfig } from "axios";
|
|
3
3
|
import { Agent, globalAgent } from "https";
|
|
4
4
|
|
|
5
5
|
type axiosConfigOptions = {
|
|
@@ -29,4 +29,17 @@ export function getAxiosConfig(token?: string, options?: axiosConfigOptions) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
return config;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getAxiosErrorData(error: AxiosError) {
|
|
35
|
+
let code = error.code || "Unknown";
|
|
36
|
+
let errorMessage = error.message || "Unspecified error";
|
|
37
|
+
if (error && error.response && error.response.data && error.response.data["odata.error"]) {
|
|
38
|
+
let errorData: { code: string; message: { value: string; }; } = error.response.data["odata.error"];
|
|
39
|
+
if (errorData.message && errorData.message.value)
|
|
40
|
+
errorMessage = errorData.message.value;
|
|
41
|
+
if (errorData && errorData.code)
|
|
42
|
+
code = errorData.code;
|
|
43
|
+
}
|
|
44
|
+
return { code: code, message: errorMessage };
|
|
32
45
|
}
|