@flashbacktech/flashbackclient 0.0.49 → 0.0.51

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.
Files changed (2) hide show
  1. package/dist/api/client.js +26 -5
  2. package/package.json +1 -1
@@ -78,18 +78,39 @@ class ApiClient {
78
78
  this.authenticateWeb3Stellar = async (token) => {
79
79
  throw new Error('Not implemented');
80
80
  };
81
- this.makeRequest = async (path, method, data) => {
81
+ this.makeRequest = async (method, path, data) => {
82
82
  const options = {
83
83
  method,
84
84
  headers: this.headers,
85
85
  body: data ? JSON.stringify(data) : null,
86
86
  };
87
- const response = await fetch(`${this.baseURL}/${path}`, options);
88
- const responseData = await response.json();
87
+ const cleanPath = path.startsWith('/') ? path.substring(1) : path;
88
+ const response = await fetch(`${this.baseURL}/${cleanPath}`, options);
89
+ // If response is not ok, handle it before trying to parse JSON
89
90
  if (!response.ok) {
90
- throw new HttpError(response.status, response.statusText, responseData);
91
+ let errorData = null;
92
+ // Only try to parse JSON if we have content
93
+ const contentType = response.headers.get('content-type');
94
+ if (contentType && contentType.includes('application/json')) {
95
+ try {
96
+ const text = await response.text();
97
+ errorData = text ? JSON.parse(text) : null; // Parse if not empty
98
+ }
99
+ catch (e) {
100
+ console.debug('Failed to parse error response:', e);
101
+ }
102
+ }
103
+ throw new HttpError(response.status, response.statusText, errorData);
104
+ }
105
+ // For successful responses, parse JSON if we have content
106
+ try {
107
+ const text = await response.text();
108
+ return text ? JSON.parse(text) : null;
109
+ }
110
+ catch (e) {
111
+ console.error('Failed to parse success response:', e);
112
+ throw new Error('Invalid JSON response from server');
91
113
  }
92
- return responseData;
93
114
  };
94
115
  ////// Auth API
95
116
  this.authenticateGoogle = async (token) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flashbacktech/flashbackclient",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },