@naturalcycles/js-lib 14.153.4 → 14.154.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.
@@ -99,9 +99,7 @@ class Fetcher {
99
99
  async fetch(opt) {
100
100
  const res = await this.doFetch(opt);
101
101
  if (res.err) {
102
- if (res.req.throwHttpErrors)
103
- throw res.err;
104
- return res;
102
+ throw res.err;
105
103
  }
106
104
  return res.body;
107
105
  }
@@ -169,6 +167,7 @@ class Fetcher {
169
167
  res.fetchResponse = undefined;
170
168
  }
171
169
  res.statusFamily = this.getStatusFamily(res);
170
+ res.statusCode = res.fetchResponse?.status;
172
171
  if (res.fetchResponse?.ok) {
173
172
  await this.onOkResponse(res, timeout);
174
173
  }
@@ -433,7 +432,6 @@ class Fetcher {
433
432
  mode: 'void',
434
433
  searchParams: {},
435
434
  timeoutSeconds: 30,
436
- throwHttpErrors: true,
437
435
  retryPost: false,
438
436
  retry3xx: false,
439
437
  retry4xx: false,
@@ -463,7 +461,6 @@ class Fetcher {
463
461
  const req = {
464
462
  ...(0, object_util_1._pick)(this.cfg, [
465
463
  'timeoutSeconds',
466
- 'throwHttpErrors',
467
464
  'retryPost',
468
465
  'retry4xx',
469
466
  'retry5xx',
@@ -89,7 +89,6 @@ export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers
89
89
  fullUrl: string;
90
90
  init: RequestInitNormalized;
91
91
  mode: FetcherMode;
92
- throwHttpErrors: boolean;
93
92
  timeoutSeconds: number;
94
93
  retry: FetcherRetryOptions;
95
94
  retryPost: boolean;
@@ -106,7 +105,6 @@ export interface FetcherOptions {
106
105
  */
107
106
  url?: string;
108
107
  baseUrl?: string;
109
- throwHttpErrors?: boolean;
110
108
  /**
111
109
  * Default: 30.
112
110
  *
@@ -170,6 +168,7 @@ export interface FetcherSuccessResponse<BODY = unknown> {
170
168
  fetchResponse: Response;
171
169
  body: BODY;
172
170
  req: FetcherRequest;
171
+ statusCode: number;
173
172
  statusFamily?: HttpStatusFamily;
174
173
  retryStatus: FetcherRetryStatus;
175
174
  signature: string;
@@ -180,6 +179,7 @@ export interface FetcherErrorResponse<BODY = unknown> {
180
179
  fetchResponse?: Response;
181
180
  body?: BODY;
182
181
  req: FetcherRequest;
182
+ statusCode?: number;
183
183
  statusFamily?: HttpStatusFamily;
184
184
  retryStatus: FetcherRetryStatus;
185
185
  signature: string;
@@ -83,9 +83,7 @@ export class Fetcher {
83
83
  async fetch(opt) {
84
84
  const res = await this.doFetch(opt);
85
85
  if (res.err) {
86
- if (res.req.throwHttpErrors)
87
- throw res.err;
88
- return res;
86
+ throw res.err;
89
87
  }
90
88
  return res.body;
91
89
  }
@@ -95,7 +93,7 @@ export class Fetcher {
95
93
  * Use this method instead of `throwHttpErrors: false` or try-catching.
96
94
  */
97
95
  async doFetch(opt) {
98
- var _a;
96
+ var _a, _b;
99
97
  const req = this.normalizeOptions(opt);
100
98
  const { logger } = this.cfg;
101
99
  const { timeoutSeconds, init: { method }, } = req;
@@ -154,7 +152,8 @@ export class Fetcher {
154
152
  res.fetchResponse = undefined;
155
153
  }
156
154
  res.statusFamily = this.getStatusFamily(res);
157
- if ((_a = res.fetchResponse) === null || _a === void 0 ? void 0 : _a.ok) {
155
+ res.statusCode = (_a = res.fetchResponse) === null || _a === void 0 ? void 0 : _a.status;
156
+ if ((_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.ok) {
158
157
  await this.onOkResponse(res, timeout);
159
158
  }
160
159
  else {
@@ -423,7 +422,6 @@ export class Fetcher {
423
422
  mode: 'void',
424
423
  searchParams: {},
425
424
  timeoutSeconds: 30,
426
- throwHttpErrors: true,
427
425
  retryPost: false,
428
426
  retry3xx: false,
429
427
  retry4xx: false,
@@ -452,7 +450,6 @@ export class Fetcher {
452
450
  normalizeOptions(opt) {
453
451
  const req = Object.assign(Object.assign(Object.assign(Object.assign({}, _pick(this.cfg, [
454
452
  'timeoutSeconds',
455
- 'throwHttpErrors',
456
453
  'retryPost',
457
454
  'retry4xx',
458
455
  'retry5xx',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.153.4",
3
+ "version": "14.154.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -117,7 +117,6 @@ export interface FetcherRequest
117
117
  fullUrl: string
118
118
  init: RequestInitNormalized
119
119
  mode: FetcherMode
120
- throwHttpErrors: boolean
121
120
  timeoutSeconds: number
122
121
  retry: FetcherRetryOptions
123
122
  retryPost: boolean
@@ -138,7 +137,6 @@ export interface FetcherOptions {
138
137
 
139
138
  baseUrl?: string
140
139
 
141
- throwHttpErrors?: boolean
142
140
  /**
143
141
  * Default: 30.
144
142
  *
@@ -216,6 +214,7 @@ export interface FetcherSuccessResponse<BODY = unknown> {
216
214
  fetchResponse: Response
217
215
  body: BODY
218
216
  req: FetcherRequest
217
+ statusCode: number
219
218
  statusFamily?: HttpStatusFamily
220
219
  retryStatus: FetcherRetryStatus
221
220
  signature: string
@@ -227,6 +226,7 @@ export interface FetcherErrorResponse<BODY = unknown> {
227
226
  fetchResponse?: Response
228
227
  body?: BODY
229
228
  req: FetcherRequest
229
+ statusCode?: number
230
230
  statusFamily?: HttpStatusFamily
231
231
  retryStatus: FetcherRetryStatus
232
232
  signature: string
@@ -153,8 +153,7 @@ export class Fetcher {
153
153
  async fetch<T = unknown>(opt: FetcherOptions): Promise<T> {
154
154
  const res = await this.doFetch<T>(opt)
155
155
  if (res.err) {
156
- if (res.req.throwHttpErrors) throw res.err
157
- return res as any
156
+ throw res.err
158
157
  }
159
158
  return res.body
160
159
  }
@@ -234,6 +233,7 @@ export class Fetcher {
234
233
  res.fetchResponse = undefined
235
234
  }
236
235
  res.statusFamily = this.getStatusFamily(res)
236
+ res.statusCode = res.fetchResponse?.status
237
237
 
238
238
  if (res.fetchResponse?.ok) {
239
239
  await this.onOkResponse(res as FetcherResponse<T> & { fetchResponse: Response }, timeout)
@@ -534,7 +534,6 @@ export class Fetcher {
534
534
  mode: 'void',
535
535
  searchParams: {},
536
536
  timeoutSeconds: 30,
537
- throwHttpErrors: true,
538
537
  retryPost: false,
539
538
  retry3xx: false,
540
539
  retry4xx: false,
@@ -569,7 +568,6 @@ export class Fetcher {
569
568
  const req: FetcherRequest = {
570
569
  ..._pick(this.cfg, [
571
570
  'timeoutSeconds',
572
- 'throwHttpErrors',
573
571
  'retryPost',
574
572
  'retry4xx',
575
573
  'retry5xx',