@finteqhub/sdk-js 0.12.0-beta.1 → 0.12.0-beta.2

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/README.md CHANGED
@@ -33,10 +33,10 @@ interface RetryOptions {
33
33
 
34
34
  Network errors (the browser could not reach the server at all, e.g. `TypeError: Failed to fetch`, or the connection dropped while the response body was being read) are always retried too.
35
35
 
36
- Every retry attempt is reported with `console.warn`. When a request finally fails, the SDK logs `console.error` with a full diagnostic dump and rejects with a `RequestError` whose `diagnostics` field carries the same payload — include it in your error reporting. `diagnostics.kind` tells the failure class apart:
36
+ Every retry attempt is reported with `console.warn`. When a request finally fails, the SDK logs `console.error` (`sdk-js: request failed: <message>`) with a full diagnostic dump and rejects with a `RequestError` whose `diagnostics` field carries the same payload — include it in your error reporting. `diagnostics.kind` tells the failure class apart:
37
37
 
38
38
  - `"network"` — the browser never got a complete response (e.g. `TypeError: Failed to fetch`, or the body could not be read); `diagnostics.error` describes the thrown error, `diagnostics.response.status` is present when headers had arrived before the failure, `message` is `request to <url> failed after N attempt(s): ...`;
39
- - `"http_error"` — an error response (non-200 status, or an `error` field in the body); `message` is the error text from the response body (or `unexpected response status <code>` when the body has none), `diagnostics.response.status` carries the HTTP status;
39
+ - `"http_error"` — an error response (non-200 status, or an `error` field in the body); `message` is the error text from the response body (or `unexpected response status <code>` when the body has none), `diagnostics.response.status` carries the HTTP status and `diagnostics.response.error` the error text from the body;
40
40
  - `"invalid_json"` — the response body is not valid JSON; both `diagnostics.error` (the parse error; its message follows the same policy as the body — sanitized for non-200, omitted for 200 responses) and `diagnostics.response` are set.
41
41
 
42
42
  Every `diagnostics` payload also includes:
@@ -44,6 +44,7 @@ Every `diagnostics` payload also includes:
44
44
  - `sdkVersion`;
45
45
  - `request`: url, method, `x-request-id`, session id, and per-attempt log `attempts: [{ durationMs, status?, error? }]` — attempt durations help tell an instant failure (DNS/connection refused) from a hang (timeout/handshake);
46
46
  - `response.body` for non-200 responses — truncated to 500 chars with long digit runs masked (`***`); the body of a 200 response is never included since it may carry session credentials; the request body is never included anywhere;
47
+ - `response.error` — the `error` field of the response body, for any status (including a 200 response with an `error` field); it is a business error text, so it is neither truncated nor masked;
47
48
  - `environment`: `navigator.onLine`, `document.visibilityState`, `navigator.connection` (`effectiveType`/`rtt`/`downlink`, Chromium only), timestamp.
48
49
 
49
50
  Diagnostics are collected regardless of whether retries are enabled.
@@ -28,6 +28,7 @@ export declare type RequestDiagnostics = {
28
28
  response?: {
29
29
  status: number;
30
30
  body?: string;
31
+ error?: string;
31
32
  };
32
33
  request: {
33
34
  url: string;
@@ -136,10 +136,10 @@ export class FinteqHubProcessing {
136
136
  ? sanitizeBody(e.message)
137
137
  : "parse error message omitted (200 response body may carry credentials)",
138
138
  };
139
- throw this.responseError("invalid_json", `request to ${url} returned invalid JSON (status ${response.status})`, url, options, attempts, response, body, parseError);
139
+ throw this.responseError("invalid_json", `request to ${url} returned invalid JSON (status ${response.status})`, url, options, attempts, { status: response.status, body }, parseError);
140
140
  }
141
141
  if ((result === null || result === void 0 ? void 0 : result.error) || response.status !== 200) {
142
- throw this.responseError("http_error", (result === null || result === void 0 ? void 0 : result.error) || `unexpected response status ${response.status}`, url, options, attempts, response, body);
142
+ throw this.responseError("http_error", (result === null || result === void 0 ? void 0 : result.error) || `unexpected response status ${response.status}`, url, options, attempts, { status: response.status, body, error: result === null || result === void 0 ? void 0 : result.error });
143
143
  }
144
144
  return result;
145
145
  });
@@ -166,9 +166,10 @@ export class FinteqHubProcessing {
166
166
  // status is known when the failure happened while reading the body of a received response
167
167
  attempts.push({ durationMs: Date.now() - startedAt, status: response === null || response === void 0 ? void 0 : response.status, error: e.message });
168
168
  if (attempt > retryCount) {
169
- const diagnostics = this.collectDiagnostics("network", url, options, attempts, e, response);
170
- console.error("sdk-js: request failed", diagnostics);
171
- throw new RequestError(`request to ${url} failed after ${attempt} attempt(s): ${e.message}`, diagnostics);
169
+ const message = `request to ${url} failed after ${attempt} attempt(s): ${e.message}`;
170
+ const diagnostics = this.collectDiagnostics("network", url, options, attempts, e, response ? { status: response.status } : undefined);
171
+ console.error(`sdk-js: request failed: ${message}`, diagnostics);
172
+ throw new RequestError(message, diagnostics);
172
173
  }
173
174
  reason = e.message;
174
175
  }
@@ -188,12 +189,12 @@ export class FinteqHubProcessing {
188
189
  }
189
190
  });
190
191
  }
191
- responseError(kind, message, url, options, attempts, response, body, error) {
192
- const diagnostics = this.collectDiagnostics(kind, url, options, attempts, error, response, body);
193
- console.error("sdk-js: request failed", diagnostics);
192
+ responseError(kind, message, url, options, attempts, response, error) {
193
+ const diagnostics = this.collectDiagnostics(kind, url, options, attempts, error, response);
194
+ console.error(`sdk-js: request failed: ${message}`, diagnostics);
194
195
  return new RequestError(message, diagnostics);
195
196
  }
196
- collectDiagnostics(kind, url, options, attempts, error, response, body) {
197
+ collectDiagnostics(kind, url, options, attempts, error, response) {
197
198
  const connection = navigator.connection;
198
199
  return {
199
200
  kind,
@@ -206,7 +207,7 @@ export class FinteqHubProcessing {
206
207
  cause: error.cause,
207
208
  }
208
209
  : undefined,
209
- response: response ? { status: response.status, body } : undefined,
210
+ response,
210
211
  request: {
211
212
  url,
212
213
  method: options.method,
@@ -1,3 +1,3 @@
1
1
  export declare const SDK_HEADER_NAME = "X-Finteqhub-SDK";
2
- export declare const SDK_VERSION = "0.12.0-beta.1";
2
+ export declare const SDK_VERSION = "0.12.0-beta.2";
3
3
  export declare const SDK_HEADER_VALUE: string;
@@ -1,3 +1,3 @@
1
1
  export const SDK_HEADER_NAME = "X-Finteqhub-SDK";
2
- export const SDK_VERSION = "0.12.0-beta.1";
2
+ export const SDK_VERSION = "0.12.0-beta.2";
3
3
  export const SDK_HEADER_VALUE = `sdk-js/${SDK_VERSION}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finteqhub/sdk-js",
3
- "version": "0.12.0-beta.1",
3
+ "version": "0.12.0-beta.2",
4
4
  "description": "SDK for interacting with FinteqHub processing API",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",