@recapi/client 0.11.1 → 0.11.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 +7 -1
- package/index.d.ts +3 -1
- package/package.json +1 -1
- package/src/transport.js +11 -4
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ are, gzipped, and browsers cache them:
|
|
|
35
35
|
|
|
36
36
|
```html
|
|
37
37
|
<script type="module">
|
|
38
|
-
import { createClient } from 'https://api.example.com/sdk/0.11.
|
|
38
|
+
import { createClient } from 'https://api.example.com/sdk/0.11.2/index.js';
|
|
39
39
|
|
|
40
40
|
const recapi = createClient({ apiKey: 'rk_pub_…', baseUrl: 'https://api.example.com', consent: false });
|
|
41
41
|
// From your cookie banner, once the visitor agrees: recapi.setConsent(true).
|
|
@@ -758,6 +758,10 @@ transient failures apart. `recommend()` and `popular()` resolve with a
|
|
|
758
758
|
list instead of rejecting on `network`, `timeout`, 5xx, 429, 401 and 403
|
|
759
759
|
errors, and report the error to `onError` (see [Fallback](#fallback)).
|
|
760
760
|
|
|
761
|
+
An API error also carries `docsUrl`, the address of its section on the
|
|
762
|
+
errors page, and its `message` ends with it, so the console line is a link
|
|
763
|
+
(absent from an older server and on client codes).
|
|
764
|
+
|
|
761
765
|
Each error code, its cause and its fix: [Errors](https://recapi.io/docs/errors).
|
|
762
766
|
No lists yet, empty lists, only popular items, key errors: [Troubleshooting](https://recapi.io/docs/troubleshooting).
|
|
763
767
|
Shops: the [Shopify](https://recapi.io/docs/shopify), [WooCommerce](https://recapi.io/docs/woocommerce) and [Magento](https://recapi.io/docs/magento) guides.
|
|
@@ -1048,6 +1052,8 @@ minifier, to keep zero dev dependencies.
|
|
|
1048
1052
|
|
|
1049
1053
|
## Changes
|
|
1050
1054
|
|
|
1055
|
+
- 2026-11-19: version 0.11.2. An API error's `docsUrl` is the address of
|
|
1056
|
+
its section on the errors page, and its message ends with it.
|
|
1051
1057
|
- 2026-11-19: version 0.11.1. No code change: this page's links lead to
|
|
1052
1058
|
the public docs, and an errors section names the errors and
|
|
1053
1059
|
troubleshooting pages.
|
package/index.d.ts
CHANGED
|
@@ -192,7 +192,7 @@ export class RecapiError extends Error {
|
|
|
192
192
|
constructor(
|
|
193
193
|
code: string,
|
|
194
194
|
message: string,
|
|
195
|
-
extra?: { status?: number; retryAfterMs?: number; details?: unknown; cause?: unknown }
|
|
195
|
+
extra?: { status?: number; retryAfterMs?: number; details?: unknown; cause?: unknown; docsUrl?: string }
|
|
196
196
|
);
|
|
197
197
|
readonly name: 'RecapiError';
|
|
198
198
|
/** API code (`invalid_request`, `rate_limited`, …) or client code (`network`, `timeout`, `invalid_response`, `event_rejected`, `queue_overflow`). */
|
|
@@ -201,6 +201,8 @@ export class RecapiError extends Error {
|
|
|
201
201
|
status: number;
|
|
202
202
|
retryAfterMs?: number;
|
|
203
203
|
details?: unknown;
|
|
204
|
+
/** The errors page's section for this code, sent by the API (absent from older servers and on client codes). `message` ends with it. */
|
|
205
|
+
docsUrl?: string;
|
|
204
206
|
readonly retryable: boolean;
|
|
205
207
|
}
|
|
206
208
|
|
package/package.json
CHANGED
package/src/transport.js
CHANGED
|
@@ -38,15 +38,19 @@ export class RecapiError extends Error {
|
|
|
38
38
|
* or a client code (`network`, `timeout`, `invalid_response`,
|
|
39
39
|
* `event_rejected`, `queue_overflow`).
|
|
40
40
|
* @param {string} message
|
|
41
|
-
* @param {{ status?: number, retryAfterMs?: number, details?: unknown, cause?: unknown }} [extra]
|
|
41
|
+
* @param {{ status?: number, retryAfterMs?: number, details?: unknown, cause?: unknown, docsUrl?: string }} [extra]
|
|
42
42
|
*/
|
|
43
|
-
constructor(code, message, { status = 0, retryAfterMs, details, cause } = {}) {
|
|
44
|
-
|
|
43
|
+
constructor(code, message, { status = 0, retryAfterMs, details, cause, docsUrl } = {}) {
|
|
44
|
+
// The address ends the message: a browser console makes it a link in
|
|
45
|
+
// the line the error prints, and an onError that logs message gets it too.
|
|
46
|
+
super(docsUrl ? `${message}, see ${docsUrl}` : message, cause === undefined ? undefined : { cause });
|
|
45
47
|
this.name = 'RecapiError';
|
|
46
48
|
this.code = code;
|
|
47
49
|
this.status = status;
|
|
48
50
|
this.retryAfterMs = retryAfterMs;
|
|
49
51
|
this.details = details;
|
|
52
|
+
/** The errors page's section for this code, from the API's body; undefined when it sent none. */
|
|
53
|
+
this.docsUrl = docsUrl || undefined;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
/**
|
|
@@ -162,7 +166,10 @@ function httpError(response, json) {
|
|
|
162
166
|
const status = response.status;
|
|
163
167
|
const code = json?.error?.code || CODE_BY_STATUS[status] || (status >= 500 ? 'internal' : 'http_error');
|
|
164
168
|
const message = json?.error?.message || `HTTP ${status}`;
|
|
165
|
-
|
|
169
|
+
// Only a string: an older server sends none, and a proxy's odd body must
|
|
170
|
+
// not put an object in the message.
|
|
171
|
+
const docsUrl = typeof json?.error?.docs_url === 'string' ? json.error.docs_url : undefined;
|
|
172
|
+
return new RecapiError(code, message, { status, retryAfterMs: retryAfter(response), docsUrl });
|
|
166
173
|
}
|
|
167
174
|
|
|
168
175
|
function retryAfter(response) {
|