@myapihq/sdk 1.0.39 → 1.0.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/client.js +5 -2
- package/package.json +1 -1
- package/src/client.ts +5 -2
package/dist/client.js
CHANGED
|
@@ -40,12 +40,15 @@ async function request(method, url, apiKey, body) {
|
|
|
40
40
|
throw new MyApiError('invalid_json_response', response.status);
|
|
41
41
|
}
|
|
42
42
|
if (!response.ok) {
|
|
43
|
-
const
|
|
43
|
+
const err = result?.error;
|
|
44
|
+
const code = typeof err === 'object' ? (err?.code || 'unknown_error') : (err || 'unknown_error');
|
|
44
45
|
throw new MyApiError(code, response.status);
|
|
45
46
|
}
|
|
46
47
|
const apiResponse = result;
|
|
47
48
|
if (!apiResponse.success) {
|
|
48
|
-
|
|
49
|
+
const err = apiResponse.error;
|
|
50
|
+
const code = typeof err === 'object' ? (err?.code || 'unknown_error') : (err || 'unknown_error');
|
|
51
|
+
throw new MyApiError(code, response.status);
|
|
49
52
|
}
|
|
50
53
|
return apiResponse.data;
|
|
51
54
|
}
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -46,13 +46,16 @@ export async function request<T>(
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
if (!response.ok) {
|
|
49
|
-
const
|
|
49
|
+
const err = result?.error;
|
|
50
|
+
const code = typeof err === 'object' ? (err?.code || 'unknown_error') : (err || 'unknown_error');
|
|
50
51
|
throw new MyApiError(code, response.status);
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
const apiResponse = result as ApiResponse<T>;
|
|
54
55
|
if (!apiResponse.success) {
|
|
55
|
-
|
|
56
|
+
const err = apiResponse.error as any;
|
|
57
|
+
const code = typeof err === 'object' ? (err?.code || 'unknown_error') : (err || 'unknown_error');
|
|
58
|
+
throw new MyApiError(code, response.status);
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
return apiResponse.data as T;
|