@ethersphere/bee-js 13.1.0 → 13.1.1-upcoming.g29c89d7

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.
@@ -43,6 +43,7 @@ async function loadRecursively(node, bee, options, requestOptions) {
43
43
  const loaded = CoreMantarayNode.unmarshalFromData(data, fork.node.selfAddress);
44
44
  fork.node.targetAddress = loaded.targetAddress;
45
45
  fork.node.forks = loaded.forks;
46
+ fork.node.obfuscationKey = loaded.obfuscationKey;
46
47
  fork.node.path = fork.prefix;
47
48
  fork.node.parent = node;
48
49
  await loadRecursively(fork.node, bee, options, requestOptions);
@@ -1,12 +1,14 @@
1
1
  export class BeeError extends Error {
2
2
  constructor(message) {
3
3
  super(message);
4
+ this.name = 'BeeError';
4
5
  }
5
6
  }
6
7
  export class BeeArgumentError extends BeeError {
7
8
  constructor(message, value) {
8
9
  super(message);
9
10
  this.value = value;
11
+ this.name = 'BeeArgumentError';
10
12
  }
11
13
  }
12
14
  export class BeeResponseError extends BeeError {
@@ -17,6 +19,7 @@ export class BeeResponseError extends BeeError {
17
19
  this.responseBody = responseBody;
18
20
  this.status = status;
19
21
  this.statusText = statusText;
22
+ this.name = 'BeeResponseError';
20
23
  this.response = {
21
24
  status,
22
25
  data: responseBody,
@@ -51,7 +51,7 @@ export async function http(options, config) {
51
51
  params: requestConfig.params
52
52
  });
53
53
  const res = await fetch(url, requestConfig);
54
- if (!res.ok) await throwHttpError(method, url, res, requestConfig.responseType);
54
+ if (!res.ok) await throwHttpError(method, url, res);
55
55
  return toBeeResponse(res, requestConfig.responseType);
56
56
  } catch (e) {
57
57
  if (e instanceof BeeResponseError) throw e;
@@ -86,13 +86,22 @@ function attachBody(config) {
86
86
  };
87
87
  }
88
88
  }
89
- async function throwHttpError(method, url, res, responseType) {
90
- const errBody = await toBeeResponse(res, responseType).catch(() => ({
91
- data: undefined
92
- }));
93
- const bodyMsg = typeof errBody.data === 'string' ? errBody.data : JSON.stringify(errBody.data);
94
- const message = bodyMsg && bodyMsg !== 'undefined' ? `${res.statusText}: ${bodyMsg}` : res.statusText;
95
- throw new BeeResponseError(method, url, message, errBody.data, res.status, res.statusText);
89
+ async function throwHttpError(method, url, res) {
90
+ const data = await readErrorBody(res);
91
+ const bodyMsg = typeof data === 'string' ? data : JSON.stringify(data);
92
+ const message = bodyMsg ? `${res.statusText}: ${bodyMsg}` : res.statusText;
93
+ throw new BeeResponseError(method, url, message, data, res.status, res.statusText);
94
+ }
95
+ async function readErrorBody(res) {
96
+ const raw = await res.text().catch(() => '');
97
+ if (!raw) {
98
+ return undefined;
99
+ }
100
+ try {
101
+ return JSON.parse(raw);
102
+ } catch {
103
+ return raw;
104
+ }
96
105
  }
97
106
  function toBeeError(err, method, url) {
98
107
  if (err.name === 'AbortError') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "13.1.0",
3
+ "version": "13.1.1-upcoming.g29c89d7",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -75,7 +75,7 @@
75
75
  "debug": "^4.4.3",
76
76
  "isomorphic-ws": "^5.0.0",
77
77
  "semver": "^7.3.5",
78
- "@ethersphere/core-sdk": "^0.1.1",
78
+ "@ethersphere/core-sdk": "^0.2.1",
79
79
  "ws": "^8.21.0",
80
80
  "zod": "^4.4.3"
81
81
  },