clearpostcode 1.0.0 → 2.0.0
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 +189 -38
- package/dist/cjs/addresses.d.ts +28 -0
- package/dist/cjs/addresses.js +64 -0
- package/dist/cjs/browser.d.ts +39 -0
- package/dist/cjs/browser.js +54 -0
- package/dist/cjs/client.d.ts +146 -0
- package/dist/cjs/client.js +188 -0
- package/dist/cjs/errors.d.ts +73 -0
- package/dist/cjs/errors.js +111 -0
- package/dist/cjs/generated.d.ts +546 -0
- package/dist/cjs/generated.js +63 -0
- package/dist/cjs/http.d.ts +62 -0
- package/dist/cjs/http.js +173 -0
- package/dist/cjs/index.d.ts +24 -0
- package/dist/cjs/index.js +54 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/page.d.ts +20 -0
- package/dist/cjs/page.js +39 -0
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +24 -0
- package/dist/esm/addresses.d.ts +28 -0
- package/dist/esm/addresses.js +47 -0
- package/dist/esm/browser.d.ts +39 -0
- package/dist/esm/browser.js +33 -0
- package/dist/esm/client.d.ts +146 -0
- package/dist/esm/client.js +169 -0
- package/dist/esm/errors.d.ts +73 -0
- package/dist/esm/errors.js +92 -0
- package/dist/esm/generated.d.ts +546 -0
- package/dist/esm/generated.js +42 -0
- package/dist/esm/http.d.ts +62 -0
- package/dist/esm/http.js +161 -0
- package/dist/esm/index.d.ts +24 -0
- package/dist/esm/index.js +37 -0
- package/dist/esm/page.d.ts +20 -0
- package/dist/esm/page.js +17 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.js +2 -0
- package/package.json +43 -13
- package/index.d.ts +0 -121
- package/index.js +0 -88
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var client_exports = {};
|
|
20
|
+
__export(client_exports, {
|
|
21
|
+
Account: () => Account,
|
|
22
|
+
Areas: () => Areas,
|
|
23
|
+
BULK_POINTS: () => BULK_POINTS,
|
|
24
|
+
BULK_POSTCODES: () => BULK_POSTCODES,
|
|
25
|
+
Client: () => Client,
|
|
26
|
+
Outcodes: () => Outcodes,
|
|
27
|
+
Places: () => Places,
|
|
28
|
+
Postcodes: () => Postcodes,
|
|
29
|
+
Sectors: () => Sectors,
|
|
30
|
+
transportConfig: () => transportConfig
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(client_exports);
|
|
33
|
+
var import_generated = require("./generated.js");
|
|
34
|
+
var import_http = require("./http.js");
|
|
35
|
+
var import_page = require("./page.js");
|
|
36
|
+
var import_addresses = require("./addresses.js");
|
|
37
|
+
var import_errors = require("./errors.js");
|
|
38
|
+
const BULK_POSTCODES = 100;
|
|
39
|
+
const BULK_POINTS = 20;
|
|
40
|
+
const found = (item) => Array.isArray(item.result) ? item.result.length > 0 : item.result !== null;
|
|
41
|
+
async function chunked(items, size, send) {
|
|
42
|
+
const data = [];
|
|
43
|
+
const requestIds = [];
|
|
44
|
+
let meta = null;
|
|
45
|
+
let rateLimit = null;
|
|
46
|
+
for (let i = 0; i < items.length; i += size) {
|
|
47
|
+
let r;
|
|
48
|
+
try {
|
|
49
|
+
r = await send(items.slice(i, i + size));
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (e instanceof import_errors.ClearPostcodeError)
|
|
52
|
+
e.partial = { data, meta, requestIds };
|
|
53
|
+
throw e;
|
|
54
|
+
}
|
|
55
|
+
data.push(...r.data);
|
|
56
|
+
requestIds.push(r.requestId);
|
|
57
|
+
rateLimit = r.rateLimit;
|
|
58
|
+
meta = { ...r.meta, sent: (meta?.sent ?? 0) + (r.meta.sent ?? r.data.length), found: (meta?.found ?? 0) + (r.meta.found ?? r.data.filter(found).length) };
|
|
59
|
+
}
|
|
60
|
+
return { data, meta, requestIds, rateLimit };
|
|
61
|
+
}
|
|
62
|
+
const fieldsOf = (fields) => fields?.length ? fields.join(",") : void 0;
|
|
63
|
+
class Postcodes {
|
|
64
|
+
#t;
|
|
65
|
+
constructor(transport) {
|
|
66
|
+
this.#t = transport;
|
|
67
|
+
}
|
|
68
|
+
lookup(postcode, params = {}, options = {}) {
|
|
69
|
+
return this.#t.request("getPostcode", { path: { postcode }, query: { fields: fieldsOf(params.fields) } }, options);
|
|
70
|
+
}
|
|
71
|
+
/** Is the format valid, is it in the current edition, is it live? Never throws for a wrong postcode. */
|
|
72
|
+
validate(postcode, options = {}) {
|
|
73
|
+
return this.#t.request("validatePostcode", { path: { postcode } }, options);
|
|
74
|
+
}
|
|
75
|
+
/** Live postcodes nearest this one, nearest first. */
|
|
76
|
+
nearest(postcode, params = {}, options = {}) {
|
|
77
|
+
return this.#t.request("nearestToPostcode", { path: { postcode }, query: { radius: params.radius, limit: params.limit } }, options);
|
|
78
|
+
}
|
|
79
|
+
/** Live postcodes nearest a point (reverse geocoding), out to 20 km. */
|
|
80
|
+
reverse(point, options = {}) {
|
|
81
|
+
return this.#t.request("reverseGeocode", { query: { lat: point.latitude, lon: point.longitude, radius: point.radius, limit: point.limit } }, options);
|
|
82
|
+
}
|
|
83
|
+
bulk(postcodes, params = {}, options = {}) {
|
|
84
|
+
return chunked(postcodes, BULK_POSTCODES, (chunk) => this.#t.request("bulkLookup", { query: { fields: fieldsOf(params.fields) }, body: { postcodes: chunk } }, options));
|
|
85
|
+
}
|
|
86
|
+
/** Nearest postcodes for any number of points, sent 20 a call. Needs a secret key. */
|
|
87
|
+
bulkReverse(points, options = {}) {
|
|
88
|
+
return chunked(points, BULK_POINTS, (chunk) => this.#t.request("bulkReverse", { body: { points: chunk.map((p) => ({ lat: p.latitude, lon: p.longitude, radius: p.radius, limit: p.limit })) } }, options));
|
|
89
|
+
}
|
|
90
|
+
/** Postcodes (or districts, for 1 to 4 characters) that start with what has been typed. Free. */
|
|
91
|
+
autocomplete(q, params = {}, options = {}) {
|
|
92
|
+
return this.#t.request("autocomplete", { query: { q, limit: params.limit } }, options);
|
|
93
|
+
}
|
|
94
|
+
/** Straight-line distance between two postcodes, in kilometres and miles, with the bearing. */
|
|
95
|
+
distance(from, to, options = {}) {
|
|
96
|
+
return this.#t.request("distance", { query: { from, to } }, options);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
class Outcodes {
|
|
100
|
+
#t;
|
|
101
|
+
constructor(transport) {
|
|
102
|
+
this.#t = transport;
|
|
103
|
+
}
|
|
104
|
+
/** One district: counts, sectors, centre, councils, wards, constituencies and places. */
|
|
105
|
+
get(outcode, options = {}) {
|
|
106
|
+
return this.#t.request("getOutcode", { path: { outcode } }, options);
|
|
107
|
+
}
|
|
108
|
+
/** One page of the district's live postcodes (1 lookup a page). Needs a secret key. */
|
|
109
|
+
postcodes(outcode, params = {}, options = {}) {
|
|
110
|
+
return (0, import_page.pageOf)(this.#t, "outcodePostcodes", { path: { outcode }, query: { limit: params.limit } }, "cursor", params.cursor ?? null, options);
|
|
111
|
+
}
|
|
112
|
+
/** Every live postcode in the district, page after page. Needs a secret key. */
|
|
113
|
+
allPostcodes(outcode, params = {}, options = {}) {
|
|
114
|
+
return (0, import_page.every)(() => this.postcodes(outcode, params, options));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
class Sectors {
|
|
118
|
+
#t;
|
|
119
|
+
constructor(transport) {
|
|
120
|
+
this.#t = transport;
|
|
121
|
+
}
|
|
122
|
+
/** One sector: its live postcodes with coordinates, centre, councils and wards. */
|
|
123
|
+
get(sector, options = {}) {
|
|
124
|
+
return this.#t.request("getSector", { path: { sector } }, options);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
class Areas {
|
|
128
|
+
#t;
|
|
129
|
+
constructor(transport) {
|
|
130
|
+
this.#t = transport;
|
|
131
|
+
}
|
|
132
|
+
/** One area: its name, counts and every district in it. */
|
|
133
|
+
get(area, options = {}) {
|
|
134
|
+
return this.#t.request("getArea", { path: { area } }, options);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
class Places {
|
|
138
|
+
#t;
|
|
139
|
+
constructor(transport) {
|
|
140
|
+
this.#t = transport;
|
|
141
|
+
}
|
|
142
|
+
/** Cities, towns, villages and neighbourhoods whose name starts with `q`; accents optional. */
|
|
143
|
+
search(q, params = {}, options = {}) {
|
|
144
|
+
return this.#t.request("places", { query: { q, limit: params.limit } }, options);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
class Account {
|
|
148
|
+
#t;
|
|
149
|
+
constructor(transport) {
|
|
150
|
+
this.#t = transport;
|
|
151
|
+
}
|
|
152
|
+
/** Your plan, this period's allowance, lookups used, credits and when it resets. Free. Needs a secret key. */
|
|
153
|
+
usage(options = {}) {
|
|
154
|
+
return this.#t.request("usage", {}, options);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function transportConfig(options, key, extra) {
|
|
158
|
+
if (!options.fetch && typeof globalThis.fetch !== "function")
|
|
159
|
+
throw new TypeError("No fetch here: pass one as the fetch option.");
|
|
160
|
+
return {
|
|
161
|
+
key,
|
|
162
|
+
baseUrl: (options.baseUrl ?? import_generated.BASE_URL).replace(/\/+$/, ""),
|
|
163
|
+
timeout: options.timeout ?? 1e4,
|
|
164
|
+
maxRetries: options.maxRetries ?? 2,
|
|
165
|
+
maxRetryDelay: options.maxRetryDelay ?? 6e4,
|
|
166
|
+
fetch: options.fetch ?? globalThis.fetch.bind(globalThis),
|
|
167
|
+
...extra
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
class Client {
|
|
171
|
+
postcodes;
|
|
172
|
+
outcodes;
|
|
173
|
+
sectors;
|
|
174
|
+
areas;
|
|
175
|
+
places;
|
|
176
|
+
account;
|
|
177
|
+
addresses;
|
|
178
|
+
constructor(config) {
|
|
179
|
+
const t = new import_http.Transport(config);
|
|
180
|
+
this.postcodes = new Postcodes(t);
|
|
181
|
+
this.outcodes = new Outcodes(t);
|
|
182
|
+
this.sectors = new Sectors(t);
|
|
183
|
+
this.areas = new Areas(t);
|
|
184
|
+
this.places = new Places(t);
|
|
185
|
+
this.account = new Account(t);
|
|
186
|
+
this.addresses = new import_addresses.Addresses(t);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Meta, Problem, ProblemCode } from "./generated.js";
|
|
2
|
+
/** What a bulk call had answered (and billed) before the chunk that failed. */
|
|
3
|
+
export interface BulkPartial {
|
|
4
|
+
readonly data: unknown[];
|
|
5
|
+
readonly meta: Meta | null;
|
|
6
|
+
readonly requestIds: (string | null)[];
|
|
7
|
+
}
|
|
8
|
+
/** Every error the client throws. */
|
|
9
|
+
export declare class ClearPostcodeError extends Error {
|
|
10
|
+
name: string;
|
|
11
|
+
/** Set when a bulk call fails part-way: the chunks already answered, so nothing billed is lost. */
|
|
12
|
+
partial: BulkPartial | null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The API answered with an error: an RFC 9457 problem. `code` is the problem type ("postcode_not_found"), `requestId`
|
|
16
|
+
* the id to quote to support, `retryAfter` the seconds the API asked you to wait (429 and 503), when it said.
|
|
17
|
+
*/
|
|
18
|
+
export declare class APIError extends ClearPostcodeError {
|
|
19
|
+
name: string;
|
|
20
|
+
readonly status: number;
|
|
21
|
+
/** The problem type. New codes may appear, so match the ones you handle and let the rest through. */
|
|
22
|
+
readonly code: ProblemCode | (string & {}) | null;
|
|
23
|
+
readonly title: string | null;
|
|
24
|
+
readonly detail: string | null;
|
|
25
|
+
readonly requestId: string | null;
|
|
26
|
+
readonly retryAfter: number | null;
|
|
27
|
+
/** The problem body as the API sent it (extra members such as `parameters`, `resets` or `upgrade` included). */
|
|
28
|
+
readonly problem: Partial<Problem>;
|
|
29
|
+
readonly headers: Headers;
|
|
30
|
+
constructor(status: number, problem: Partial<Problem> | null, headers: Headers, retryAfter: number | null);
|
|
31
|
+
}
|
|
32
|
+
/** 400 or 413: a parameter, the postcode format or the body (invalid_postcode, unknown_parameter, bad_request…). */
|
|
33
|
+
export declare class BadRequestError extends APIError {
|
|
34
|
+
name: string;
|
|
35
|
+
}
|
|
36
|
+
/** 401: the key is missing where one is needed, malformed or not active (invalid_key, key_required). */
|
|
37
|
+
export declare class AuthenticationError extends APIError {
|
|
38
|
+
name: string;
|
|
39
|
+
}
|
|
40
|
+
/** 402: the period's lookups, or the address credits, are used up (quota_exceeded, address_credits_exhausted). */
|
|
41
|
+
export declare class QuotaExceededError extends APIError {
|
|
42
|
+
name: string;
|
|
43
|
+
}
|
|
44
|
+
/** 403: the key may not make this call (origin_not_allowed, publishable_key_not_allowed, address_lookup_not_enabled…). */
|
|
45
|
+
export declare class PermissionDeniedError extends APIError {
|
|
46
|
+
name: string;
|
|
47
|
+
}
|
|
48
|
+
/** 404: no such postcode, district or address (postcode_not_found, not_covered, not_found). */
|
|
49
|
+
export declare class NotFoundError extends APIError {
|
|
50
|
+
name: string;
|
|
51
|
+
}
|
|
52
|
+
/** 422: a real postcode with no coordinates (no_position: the Channel Islands and the Isle of Man). */
|
|
53
|
+
export declare class UnprocessableEntityError extends APIError {
|
|
54
|
+
name: string;
|
|
55
|
+
}
|
|
56
|
+
/** 429: too many requests, a day's keyless allowance, or the key's daily cap (rate_limited, daily_cap_reached). */
|
|
57
|
+
export declare class RateLimitError extends APIError {
|
|
58
|
+
name: string;
|
|
59
|
+
}
|
|
60
|
+
/** 5xx: a moment's trouble on the API's side (server_error, service_unavailable). Retried for you. */
|
|
61
|
+
export declare class InternalServerError extends APIError {
|
|
62
|
+
name: string;
|
|
63
|
+
}
|
|
64
|
+
/** The API could not be reached (DNS, TLS, a dropped connection). Retried for you. */
|
|
65
|
+
export declare class APIConnectionError extends ClearPostcodeError {
|
|
66
|
+
name: string;
|
|
67
|
+
}
|
|
68
|
+
/** No answer within the timeout. Retried for you. */
|
|
69
|
+
export declare class APITimeoutError extends APIConnectionError {
|
|
70
|
+
name: string;
|
|
71
|
+
}
|
|
72
|
+
/** The error class for an HTTP status. */
|
|
73
|
+
export declare function errorFor(status: number, problem: Partial<Problem> | null, headers: Headers, retryAfter: number | null): APIError;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var errors_exports = {};
|
|
20
|
+
__export(errors_exports, {
|
|
21
|
+
APIConnectionError: () => APIConnectionError,
|
|
22
|
+
APIError: () => APIError,
|
|
23
|
+
APITimeoutError: () => APITimeoutError,
|
|
24
|
+
AuthenticationError: () => AuthenticationError,
|
|
25
|
+
BadRequestError: () => BadRequestError,
|
|
26
|
+
ClearPostcodeError: () => ClearPostcodeError,
|
|
27
|
+
InternalServerError: () => InternalServerError,
|
|
28
|
+
NotFoundError: () => NotFoundError,
|
|
29
|
+
PermissionDeniedError: () => PermissionDeniedError,
|
|
30
|
+
QuotaExceededError: () => QuotaExceededError,
|
|
31
|
+
RateLimitError: () => RateLimitError,
|
|
32
|
+
UnprocessableEntityError: () => UnprocessableEntityError,
|
|
33
|
+
errorFor: () => errorFor
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(errors_exports);
|
|
36
|
+
class ClearPostcodeError extends Error {
|
|
37
|
+
name = "ClearPostcodeError";
|
|
38
|
+
/** Set when a bulk call fails part-way: the chunks already answered, so nothing billed is lost. */
|
|
39
|
+
partial = null;
|
|
40
|
+
}
|
|
41
|
+
class APIError extends ClearPostcodeError {
|
|
42
|
+
name = "APIError";
|
|
43
|
+
status;
|
|
44
|
+
/** The problem type. New codes may appear, so match the ones you handle and let the rest through. */
|
|
45
|
+
code;
|
|
46
|
+
title;
|
|
47
|
+
detail;
|
|
48
|
+
requestId;
|
|
49
|
+
retryAfter;
|
|
50
|
+
/** The problem body as the API sent it (extra members such as `parameters`, `resets` or `upgrade` included). */
|
|
51
|
+
problem;
|
|
52
|
+
headers;
|
|
53
|
+
constructor(status, problem, headers, retryAfter) {
|
|
54
|
+
const p = problem ?? {};
|
|
55
|
+
const code = typeof p.type === "string" && p.type.includes("#") ? p.type.slice(p.type.lastIndexOf("#") + 1) : null;
|
|
56
|
+
const requestId = p.request_id ?? headers.get("x-request-id");
|
|
57
|
+
super(`${status}${code ? ` ${code}` : ""}: ${p.detail ?? p.title ?? "the API answered with an error"}${requestId ? ` (request ${requestId})` : ""}`);
|
|
58
|
+
this.status = status;
|
|
59
|
+
this.code = code;
|
|
60
|
+
this.title = p.title ?? null;
|
|
61
|
+
this.detail = p.detail ?? null;
|
|
62
|
+
this.requestId = requestId;
|
|
63
|
+
this.retryAfter = retryAfter;
|
|
64
|
+
this.problem = p;
|
|
65
|
+
this.headers = headers;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
class BadRequestError extends APIError {
|
|
69
|
+
name = "BadRequestError";
|
|
70
|
+
}
|
|
71
|
+
class AuthenticationError extends APIError {
|
|
72
|
+
name = "AuthenticationError";
|
|
73
|
+
}
|
|
74
|
+
class QuotaExceededError extends APIError {
|
|
75
|
+
name = "QuotaExceededError";
|
|
76
|
+
}
|
|
77
|
+
class PermissionDeniedError extends APIError {
|
|
78
|
+
name = "PermissionDeniedError";
|
|
79
|
+
}
|
|
80
|
+
class NotFoundError extends APIError {
|
|
81
|
+
name = "NotFoundError";
|
|
82
|
+
}
|
|
83
|
+
class UnprocessableEntityError extends APIError {
|
|
84
|
+
name = "UnprocessableEntityError";
|
|
85
|
+
}
|
|
86
|
+
class RateLimitError extends APIError {
|
|
87
|
+
name = "RateLimitError";
|
|
88
|
+
}
|
|
89
|
+
class InternalServerError extends APIError {
|
|
90
|
+
name = "InternalServerError";
|
|
91
|
+
}
|
|
92
|
+
class APIConnectionError extends ClearPostcodeError {
|
|
93
|
+
name = "APIConnectionError";
|
|
94
|
+
}
|
|
95
|
+
class APITimeoutError extends APIConnectionError {
|
|
96
|
+
name = "APITimeoutError";
|
|
97
|
+
}
|
|
98
|
+
const BY_STATUS = {
|
|
99
|
+
400: BadRequestError,
|
|
100
|
+
401: AuthenticationError,
|
|
101
|
+
402: QuotaExceededError,
|
|
102
|
+
403: PermissionDeniedError,
|
|
103
|
+
404: NotFoundError,
|
|
104
|
+
413: BadRequestError,
|
|
105
|
+
422: UnprocessableEntityError,
|
|
106
|
+
429: RateLimitError
|
|
107
|
+
};
|
|
108
|
+
function errorFor(status, problem, headers, retryAfter) {
|
|
109
|
+
const E = BY_STATUS[status] ?? (status >= 500 ? InternalServerError : APIError);
|
|
110
|
+
return new E(status, problem, headers, retryAfter);
|
|
111
|
+
}
|