@oasis-path/gamma-sdk 1.0.2 → 1.0.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.
- package/dist/client.js +22 -7
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -177,16 +177,27 @@ class GammaFilesClient {
|
|
|
177
177
|
});
|
|
178
178
|
res.on('end', () => {
|
|
179
179
|
const buffer = Buffer.concat(chunks);
|
|
180
|
+
const responseText = buffer.toString();
|
|
180
181
|
if (res.statusCode && res.statusCode >= 400) {
|
|
181
182
|
let errorMessage = `HTTP ${res.statusCode}`;
|
|
183
|
+
let errorDetails = '';
|
|
182
184
|
try {
|
|
183
|
-
const errorBody = JSON.parse(
|
|
184
|
-
errorMessage = errorBody.error || errorMessage;
|
|
185
|
+
const errorBody = JSON.parse(responseText);
|
|
186
|
+
errorMessage = errorBody.error || errorBody.message || errorMessage;
|
|
187
|
+
errorDetails = errorBody.details ? `\nDetails: ${JSON.stringify(errorBody.details)}` : '';
|
|
188
|
+
// Create a more descriptive error
|
|
189
|
+
const fullError = new Error(`API Error (${res.statusCode}): ${errorMessage}${errorDetails}\nEndpoint: ${method} ${url.pathname}`);
|
|
190
|
+
fullError.statusCode = res.statusCode;
|
|
191
|
+
fullError.responseBody = errorBody;
|
|
192
|
+
reject(fullError);
|
|
185
193
|
}
|
|
186
194
|
catch {
|
|
187
|
-
|
|
195
|
+
// If response is not JSON, use raw text
|
|
196
|
+
const fullError = new Error(`API Error (${res.statusCode}): ${responseText || errorMessage}\nEndpoint: ${method} ${url.pathname}`);
|
|
197
|
+
fullError.statusCode = res.statusCode;
|
|
198
|
+
fullError.responseBody = responseText;
|
|
199
|
+
reject(fullError);
|
|
188
200
|
}
|
|
189
|
-
reject(new Error(errorMessage));
|
|
190
201
|
return;
|
|
191
202
|
}
|
|
192
203
|
if (options.binary) {
|
|
@@ -194,17 +205,21 @@ class GammaFilesClient {
|
|
|
194
205
|
}
|
|
195
206
|
else {
|
|
196
207
|
try {
|
|
197
|
-
const data = JSON.parse(
|
|
208
|
+
const data = JSON.parse(responseText);
|
|
198
209
|
resolve(data);
|
|
199
210
|
}
|
|
200
211
|
catch (err) {
|
|
201
|
-
|
|
212
|
+
const parseError = new Error(`Failed to parse response JSON from ${method} ${url.pathname}\nResponse: ${responseText.substring(0, 200)}${responseText.length > 200 ? '...' : ''}`);
|
|
213
|
+
parseError.responseText = responseText;
|
|
214
|
+
reject(parseError);
|
|
202
215
|
}
|
|
203
216
|
}
|
|
204
217
|
});
|
|
205
218
|
});
|
|
206
219
|
req.on('error', (err) => {
|
|
207
|
-
|
|
220
|
+
const networkError = new Error(`Network error for ${method} ${url.pathname}: ${err.message}`);
|
|
221
|
+
networkError.originalError = err;
|
|
222
|
+
reject(networkError);
|
|
208
223
|
});
|
|
209
224
|
if (options.body) {
|
|
210
225
|
if (options.body instanceof form_data_1.default) {
|