@machinemetrics/mm-erp-sdk 0.1.1-beta.1 → 0.1.1-beta.3
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
|
-
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/utils/http-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/utils/http-client.ts"],"names":[],"mappings":"AAGA,qBAAa,SAAU,SAAQ,KAAK;IAGzB,MAAM,EAAE,MAAM;IACd,IAAI,CAAC,EAAE,MAAM;IACb,IAAI,CAAC,EAAE,OAAO;gBAHrB,OAAO,EAAE,MAAM,EACR,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,IAAI,CAAC,EAAE,OAAO,YAAA;CAKxB;AAED,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,UAAU,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;CAC3E;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU;CAGzD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@machinemetrics/mm-erp-sdk",
|
|
3
3
|
"description": "A library for syncing data between MachineMetrics and ERP systems",
|
|
4
|
-
"version": "0.1.1-beta.
|
|
4
|
+
"version": "0.1.1-beta.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "machinemetrics",
|
|
7
7
|
"main": "dist/mm-erp-sdk.js",
|
package/src/utils/http-client.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
|
+
import logger from "../services/reporting-service/logger";
|
|
2
3
|
|
|
3
4
|
export class HTTPError extends Error {
|
|
4
5
|
constructor(
|
|
@@ -79,10 +80,26 @@ class AxiosClient implements HTTPClient {
|
|
|
79
80
|
params: config.params,
|
|
80
81
|
};
|
|
81
82
|
|
|
83
|
+
logger.info("HTTP request starting", {
|
|
84
|
+
url: config.url,
|
|
85
|
+
method: config.method,
|
|
86
|
+
baseURL: this.client.defaults.baseURL,
|
|
87
|
+
retryAttempts: this.retryAttempts
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Extra console.log for debugging
|
|
91
|
+
console.log("=== FULL URL DEBUG ===");
|
|
92
|
+
console.log("baseURL:", this.client.defaults.baseURL);
|
|
93
|
+
console.log("relative url:", config.url);
|
|
94
|
+
console.log("full constructed URL:", (this.client.defaults.baseURL || "") + config.url);
|
|
95
|
+
console.log("method:", config.method);
|
|
96
|
+
|
|
82
97
|
let lastError: unknown;
|
|
83
98
|
for (let attempt = 0; attempt <= this.retryAttempts; attempt++) {
|
|
84
99
|
try {
|
|
100
|
+
logger.info(`HTTP request attempt ${attempt + 1}/${this.retryAttempts + 1}`);
|
|
85
101
|
const response = await this.client.request<T>(axiosConfig);
|
|
102
|
+
logger.info("HTTP request succeeded", { status: response.status });
|
|
86
103
|
return {
|
|
87
104
|
data: response.data,
|
|
88
105
|
status: response.status,
|
|
@@ -90,6 +107,15 @@ class AxiosClient implements HTTPClient {
|
|
|
90
107
|
};
|
|
91
108
|
} catch (error) {
|
|
92
109
|
lastError = error;
|
|
110
|
+
logger.info(`HTTP request attempt ${attempt + 1} failed`, {
|
|
111
|
+
errorType: typeof error,
|
|
112
|
+
errorConstructor: error?.constructor?.name,
|
|
113
|
+
isAxiosError: error instanceof AxiosError,
|
|
114
|
+
message: error instanceof Error ? error.message : String(error),
|
|
115
|
+
code: (error as any)?.code,
|
|
116
|
+
status: (error as any)?.response?.status
|
|
117
|
+
});
|
|
118
|
+
|
|
93
119
|
// Don't retry on 4xx errors (client errors)
|
|
94
120
|
if (
|
|
95
121
|
error instanceof AxiosError &&
|
|
@@ -97,10 +123,13 @@ class AxiosClient implements HTTPClient {
|
|
|
97
123
|
error.response.status >= 400 &&
|
|
98
124
|
error.response.status < 500
|
|
99
125
|
) {
|
|
126
|
+
logger.info("Not retrying due to 4xx client error");
|
|
100
127
|
break;
|
|
101
128
|
}
|
|
102
129
|
// If this was the last attempt, don't wait
|
|
103
130
|
if (attempt < this.retryAttempts) {
|
|
131
|
+
const waitTime = Math.pow(2, attempt) * 1000;
|
|
132
|
+
logger.info(`Waiting ${waitTime}ms before retry`);
|
|
104
133
|
// Exponential backoff: wait 2^attempt * 1000ms
|
|
105
134
|
await new Promise((resolve) =>
|
|
106
135
|
setTimeout(resolve, Math.pow(2, attempt) * 1000)
|
|
@@ -108,6 +137,7 @@ class AxiosClient implements HTTPClient {
|
|
|
108
137
|
}
|
|
109
138
|
}
|
|
110
139
|
}
|
|
140
|
+
logger.info("HTTP request failed after all retries, throwing error");
|
|
111
141
|
throw this.handleError(lastError, config);
|
|
112
142
|
}
|
|
113
143
|
|