@hapaul/api 0.1.38 → 0.1.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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +10 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2652,6 +2652,7 @@ interface Middleware<C> {
|
|
|
2652
2652
|
onResponse?: (config: RequestConfig<any, any, C>, response: Response) => Response | Promise<Response>;
|
|
2653
2653
|
onError?: (config: RequestLooseConfig<C>, response: Response, error: {
|
|
2654
2654
|
status: number;
|
|
2655
|
+
code: string;
|
|
2655
2656
|
message: string;
|
|
2656
2657
|
}) => void;
|
|
2657
2658
|
}
|
package/dist/index.js
CHANGED
|
@@ -69,19 +69,24 @@ var Client = class {
|
|
|
69
69
|
if (contentType$1.includes("application/json")) assign(await response.json());
|
|
70
70
|
else if (contentType$1.includes("text/plain")) assign(await response.text());
|
|
71
71
|
else assign(await response.arrayBuffer());
|
|
72
|
+
const res = {
|
|
73
|
+
data,
|
|
74
|
+
error,
|
|
75
|
+
response
|
|
76
|
+
};
|
|
72
77
|
if (!isOk) {
|
|
78
|
+
let code = "";
|
|
73
79
|
let message = response.statusText;
|
|
80
|
+
if (typeof error === "object" && "code" in error) code = error.code;
|
|
74
81
|
if (typeof error === "object" && "message" in error) message = error.message;
|
|
75
82
|
for (const middleware of this.middlewares) middleware.onError?.(requestConfig, response, {
|
|
83
|
+
code,
|
|
76
84
|
status,
|
|
77
85
|
message
|
|
78
86
|
});
|
|
87
|
+
return Promise.reject(res);
|
|
79
88
|
}
|
|
80
|
-
return
|
|
81
|
-
data,
|
|
82
|
-
error,
|
|
83
|
-
response
|
|
84
|
-
};
|
|
89
|
+
return res;
|
|
85
90
|
} catch (error) {
|
|
86
91
|
throw error;
|
|
87
92
|
}
|