@taybart/corvid 0.1.19 → 0.1.21
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 +7 -3
- package/dist/network.d.ts +8 -3
- package/dist/network.js +7 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -544,7 +544,8 @@ class request {
|
|
|
544
544
|
override
|
|
545
545
|
});
|
|
546
546
|
this.log.debug(`${this.opts.method} ${url}`);
|
|
547
|
-
|
|
547
|
+
let res;
|
|
548
|
+
res = this.opts.fetch ? await this.opts.fetch(url, options) : await fetch(url, options);
|
|
548
549
|
const expect = override.expect || this.opts.expect;
|
|
549
550
|
if (res.status !== expect) {
|
|
550
551
|
const body = await res.text();
|
|
@@ -556,7 +557,11 @@ class request {
|
|
|
556
557
|
override,
|
|
557
558
|
_recurselevel: _recurselevel + 1
|
|
558
559
|
});
|
|
559
|
-
} else throw
|
|
560
|
+
} else throw {
|
|
561
|
+
message: `bad wesponse ${res.status} !== ${expect}, body: ${body}`,
|
|
562
|
+
status: res.status,
|
|
563
|
+
body
|
|
564
|
+
};
|
|
560
565
|
}
|
|
561
566
|
this.log.debug(`content type: ${res.headers.get('content-type')}`);
|
|
562
567
|
if ('application/json' === res.headers.get('content-type')) return await res.json();
|
|
@@ -577,7 +582,6 @@ class request {
|
|
|
577
582
|
this.log.debug("converting object params to class");
|
|
578
583
|
this.opts.params = new network_params(this.opts.params);
|
|
579
584
|
}
|
|
580
|
-
if (!this.opts.fetch) this.opts.fetch = window.fetch;
|
|
581
585
|
this.log.debug(`with options: ${JSON.stringify(this.opts)}`);
|
|
582
586
|
}
|
|
583
587
|
}
|
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
|
|
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:
|
|
34
|
+
opts: RequestOpts;
|
|
30
35
|
log: logger;
|
|
31
|
-
constructor(opts?:
|
|
36
|
+
constructor(opts?: RequestOpts, verbose?: boolean);
|
|
32
37
|
auth(a: string | {
|
|
33
38
|
username: string;
|
|
34
39
|
password: string;
|
package/dist/network.js
CHANGED
|
@@ -135,7 +135,8 @@ class request {
|
|
|
135
135
|
override
|
|
136
136
|
});
|
|
137
137
|
this.log.debug(`${this.opts.method} ${url}`);
|
|
138
|
-
|
|
138
|
+
let res;
|
|
139
|
+
res = this.opts.fetch ? await this.opts.fetch(url, options) : await fetch(url, options);
|
|
139
140
|
const expect = override.expect || this.opts.expect;
|
|
140
141
|
if (res.status !== expect) {
|
|
141
142
|
const body = await res.text();
|
|
@@ -147,7 +148,11 @@ class request {
|
|
|
147
148
|
override,
|
|
148
149
|
_recurselevel: _recurselevel + 1
|
|
149
150
|
});
|
|
150
|
-
} else throw
|
|
151
|
+
} else throw {
|
|
152
|
+
message: `bad wesponse ${res.status} !== ${expect}, body: ${body}`,
|
|
153
|
+
status: res.status,
|
|
154
|
+
body
|
|
155
|
+
};
|
|
151
156
|
}
|
|
152
157
|
this.log.debug(`content type: ${res.headers.get('content-type')}`);
|
|
153
158
|
if ('application/json' === res.headers.get('content-type')) return await res.json();
|
|
@@ -168,7 +173,6 @@ class request {
|
|
|
168
173
|
this.log.debug("converting object params to class");
|
|
169
174
|
this.opts.params = new network_params(this.opts.params);
|
|
170
175
|
}
|
|
171
|
-
if (!this.opts.fetch) this.opts.fetch = window.fetch;
|
|
172
176
|
this.log.debug(`with options: ${JSON.stringify(this.opts)}`);
|
|
173
177
|
}
|
|
174
178
|
}
|