@taybart/corvid 0.1.18 → 0.1.20

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/dist/index.js CHANGED
@@ -553,7 +553,11 @@ class request {
553
553
  if (401 === res.status && this.opts.onUnauthorized) {
554
554
  this.log.warn("unauthorized");
555
555
  this.opts.onUnauthorized(body);
556
- } else throw new Error(`bad response ${res.status} !== ${expect}, body: ${body}`);
556
+ } else throw {
557
+ message: `bad wesponse ${res.status} !== ${expect}, body: ${body}`,
558
+ status: res.status,
559
+ body
560
+ };
557
561
  }
558
562
  this.log.debug(`content type: ${res.headers.get('content-type')}`);
559
563
  if ('application/json' === res.headers.get('content-type')) return await res.json();
package/dist/network.d.ts CHANGED
@@ -7,8 +7,13 @@ export declare class params {
7
7
  toString(): string;
8
8
  static render(p: Object): string;
9
9
  }
10
+ export type RequestError = {
11
+ error: string;
12
+ status: number;
13
+ body: string;
14
+ };
10
15
  /*** http request ***/
11
- export type requestOpts = {
16
+ export type RequestOpts = {
12
17
  url?: string;
13
18
  type?: 'json';
14
19
  method?: 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS';
@@ -26,9 +31,9 @@ export type requestOpts = {
26
31
  fetch?: (url: string, init: RequestInit) => Promise<any>;
27
32
  };
28
33
  export declare class request {
29
- opts: requestOpts;
34
+ opts: RequestOpts;
30
35
  log: logger;
31
- constructor(opts?: requestOpts, verbose?: boolean);
36
+ constructor(opts?: RequestOpts, verbose?: boolean);
32
37
  auth(token: string | {
33
38
  username: string;
34
39
  password: string;
package/dist/network.js CHANGED
@@ -144,7 +144,11 @@ class request {
144
144
  if (401 === res.status && this.opts.onUnauthorized) {
145
145
  this.log.warn("unauthorized");
146
146
  this.opts.onUnauthorized(body);
147
- } else throw new Error(`bad response ${res.status} !== ${expect}, body: ${body}`);
147
+ } else throw {
148
+ message: `bad wesponse ${res.status} !== ${expect}, body: ${body}`,
149
+ status: res.status,
150
+ body
151
+ };
148
152
  }
149
153
  this.log.debug(`content type: ${res.headers.get('content-type')}`);
150
154
  if ('application/json' === res.headers.get('content-type')) return await res.json();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taybart/corvid",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {