@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 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 code = result?.error || 'unknown_error';
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
- throw new MyApiError(apiResponse.error || 'unknown_error', response.status);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myapihq/sdk",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
4
4
  "description": "TypeScript SDK for the MyAPI ecosystem",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
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 code = result?.error || 'unknown_error';
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
- throw new MyApiError(apiResponse.error || 'unknown_error', response.status);
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;