@afribase/afribase-js 0.2.0 → 0.2.1

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/index.js CHANGED
@@ -101,9 +101,14 @@ async function handleResponse(response) {
101
101
  if (!response.ok) {
102
102
  let errorBody;
103
103
  try {
104
- errorBody = await response.json();
104
+ const text = await response.text();
105
+ try {
106
+ errorBody = JSON.parse(text);
107
+ } catch {
108
+ errorBody = { message: text || `Request failed with status ${response.status}` };
109
+ }
105
110
  } catch {
106
- errorBody = { message: await response.text() };
111
+ errorBody = { message: `Request failed with status ${response.status}` };
107
112
  }
108
113
  return {
109
114
  data: null,
@@ -118,7 +123,9 @@ async function handleResponse(response) {
118
123
  return { data: null, error: null };
119
124
  }
120
125
  try {
121
- const data = await response.json();
126
+ const text = await response.text();
127
+ if (!text) return { data: null, error: null };
128
+ const data = JSON.parse(text);
122
129
  return { data, error: null };
123
130
  } catch {
124
131
  return { data: null, error: null };
@@ -1638,9 +1645,14 @@ var AfribaseQueryBuilder = class {
1638
1645
  if (!resp.ok) {
1639
1646
  let errorBody;
1640
1647
  try {
1641
- errorBody = await resp.json();
1648
+ const text = await resp.text();
1649
+ try {
1650
+ errorBody = JSON.parse(text);
1651
+ } catch {
1652
+ errorBody = { message: text || `Request failed with status ${resp.status}` };
1653
+ }
1642
1654
  } catch {
1643
- errorBody = { message: await resp.text() };
1655
+ errorBody = { message: `Request failed with status ${resp.status}` };
1644
1656
  }
1645
1657
  return {
1646
1658
  data: null,
@@ -1769,9 +1781,14 @@ var AfribaseRpcBuilder = class {
1769
1781
  if (!resp.ok) {
1770
1782
  let errorBody;
1771
1783
  try {
1772
- errorBody = await resp.json();
1784
+ const text = await resp.text();
1785
+ try {
1786
+ errorBody = JSON.parse(text);
1787
+ } catch {
1788
+ errorBody = { message: text || `RPC failed with status ${resp.status}` };
1789
+ }
1773
1790
  } catch {
1774
- errorBody = { message: await resp.text() };
1791
+ errorBody = { message: `RPC failed with status ${resp.status}` };
1775
1792
  }
1776
1793
  return {
1777
1794
  data: null,
package/dist/index.mjs CHANGED
@@ -26,9 +26,14 @@ async function handleResponse(response) {
26
26
  if (!response.ok) {
27
27
  let errorBody;
28
28
  try {
29
- errorBody = await response.json();
29
+ const text = await response.text();
30
+ try {
31
+ errorBody = JSON.parse(text);
32
+ } catch {
33
+ errorBody = { message: text || `Request failed with status ${response.status}` };
34
+ }
30
35
  } catch {
31
- errorBody = { message: await response.text() };
36
+ errorBody = { message: `Request failed with status ${response.status}` };
32
37
  }
33
38
  return {
34
39
  data: null,
@@ -43,7 +48,9 @@ async function handleResponse(response) {
43
48
  return { data: null, error: null };
44
49
  }
45
50
  try {
46
- const data = await response.json();
51
+ const text = await response.text();
52
+ if (!text) return { data: null, error: null };
53
+ const data = JSON.parse(text);
47
54
  return { data, error: null };
48
55
  } catch {
49
56
  return { data: null, error: null };
@@ -1563,9 +1570,14 @@ var AfribaseQueryBuilder = class {
1563
1570
  if (!resp.ok) {
1564
1571
  let errorBody;
1565
1572
  try {
1566
- errorBody = await resp.json();
1573
+ const text = await resp.text();
1574
+ try {
1575
+ errorBody = JSON.parse(text);
1576
+ } catch {
1577
+ errorBody = { message: text || `Request failed with status ${resp.status}` };
1578
+ }
1567
1579
  } catch {
1568
- errorBody = { message: await resp.text() };
1580
+ errorBody = { message: `Request failed with status ${resp.status}` };
1569
1581
  }
1570
1582
  return {
1571
1583
  data: null,
@@ -1694,9 +1706,14 @@ var AfribaseRpcBuilder = class {
1694
1706
  if (!resp.ok) {
1695
1707
  let errorBody;
1696
1708
  try {
1697
- errorBody = await resp.json();
1709
+ const text = await resp.text();
1710
+ try {
1711
+ errorBody = JSON.parse(text);
1712
+ } catch {
1713
+ errorBody = { message: text || `RPC failed with status ${resp.status}` };
1714
+ }
1698
1715
  } catch {
1699
- errorBody = { message: await resp.text() };
1716
+ errorBody = { message: `RPC failed with status ${resp.status}` };
1700
1717
  }
1701
1718
  return {
1702
1719
  data: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afribase/afribase-js",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "The official JavaScript/TypeScript client for Afribase — Auth, Database, Realtime, Storage, and Edge Functions",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",