@flashbacktech/flashbackclient 0.0.48 → 0.0.50

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.
@@ -78,18 +78,38 @@ 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
87
  const response = await fetch(`${this.baseURL}/${path}`, options);
88
- const responseData = await response.json();
88
+ // If response is not ok, handle it before trying to parse JSON
89
89
  if (!response.ok) {
90
- throw new HttpError(response.status, response.statusText, responseData);
90
+ let errorData = null;
91
+ // Only try to parse JSON if we have content
92
+ const contentType = response.headers.get('content-type');
93
+ if (contentType && contentType.includes('application/json')) {
94
+ try {
95
+ const text = await response.text();
96
+ errorData = text ? JSON.parse(text) : null; // Parse if not empty
97
+ }
98
+ catch (e) {
99
+ console.debug('Failed to parse error response:', e);
100
+ }
101
+ }
102
+ throw new HttpError(response.status, response.statusText, errorData);
103
+ }
104
+ // For successful responses, parse JSON if we have content
105
+ try {
106
+ const text = await response.text();
107
+ return text ? JSON.parse(text) : null;
108
+ }
109
+ catch (e) {
110
+ console.error('Failed to parse success response:', e);
111
+ throw new Error('Invalid JSON response from server');
91
112
  }
92
- return responseData;
93
113
  };
94
114
  ////// Auth API
95
115
  this.authenticateGoogle = async (token) => {
@@ -1,5 +1,5 @@
1
- import { ApiClient } from './client';
1
+ import { ApiClient, HttpError } from './client';
2
2
  import * as ApiTypes from './types/storage';
3
3
  import * as AuthTypes from './types/auth';
4
4
  import * as ApiInterfaces from './interfaces';
5
- export { ApiClient, ApiTypes, AuthTypes, ApiInterfaces };
5
+ export { ApiClient, ApiTypes, AuthTypes, ApiInterfaces, HttpError };
package/dist/api/index.js CHANGED
@@ -33,9 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ApiInterfaces = exports.AuthTypes = exports.ApiTypes = exports.ApiClient = void 0;
36
+ exports.HttpError = exports.ApiInterfaces = exports.AuthTypes = exports.ApiTypes = exports.ApiClient = void 0;
37
37
  const client_1 = require("./client");
38
38
  Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function () { return client_1.ApiClient; } });
39
+ Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return client_1.HttpError; } });
39
40
  const ApiTypes = __importStar(require("./types/storage"));
40
41
  exports.ApiTypes = ApiTypes;
41
42
  const AuthTypes = __importStar(require("./types/auth"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flashbacktech/flashbackclient",
3
- "version": "0.0.48",
3
+ "version": "0.0.50",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },