File tree 2 files changed +61
-1
lines changed
2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ The following methods are available.
11
11
- [ ` .send([body]) ` ] ( #send ) [ ` .sendUrlencoded(data) ` ] ( #sendurlencoded ) [ ` .sendJson(data) ` ] ( #sendjson ) [ ` .then() ` ] ( #then )
12
12
- [ ` .setResponseTransformers([]) ` ] ( #setresponsetransformers ) [ ` .setAllowedStatusCode(allowed) ` ] ( #setallowedstatuscode ) [ ` .polyfills(polyfills) ` ] ( #polyfills )
13
13
- [ ` .toObject() ` / ` .config() ` / ` .debug() ` ] ( #toobject )
14
+ - [ ` YeaResponse ` ] ( #yearesponse )
15
+ - [ ` YeaRequestError ` ] ( #yearequesterror )
14
16
15
17
## get
16
18
@@ -437,3 +439,57 @@ const config = req.toObject(); // or req.config() or req.debug()
437
439
// ],
438
440
// }
439
441
```
442
+
443
+ ## YeaResponse
444
+
445
+ Responses have the following format:
446
+
447
+ ``` js
448
+ {
449
+ headers: {
450
+ ' content-type' : ' text/html' ,
451
+ ...
452
+ },
453
+ body: ' raw body text' ,
454
+ status: 200
455
+ }
456
+ ```
457
+
458
+ By default JSON responses are decoded (see [ ` .setResponseTransformers([]) ` ] ( #setresponsetransformers ) ), in which case there is an extra property:
459
+
460
+ ``` js
461
+ {
462
+ headers: {
463
+ ' content-type' : ' application/json' ,
464
+ ...
465
+ },
466
+ body: ' {"foo":"bar"}' ,
467
+ status: 200
468
+ data: {
469
+ foo: ' bar'
470
+ }
471
+ }
472
+ ```
473
+
474
+ ## YeaRequestError
475
+
476
+ If a request fails, the Promise is rejected with an error which includes an extra ` response ` property:
477
+
478
+ ``` js
479
+ {
480
+ message: ' Request failed with status 500' ,
481
+ stack: ' ...' ,
482
+ // ...
483
+ response: {
484
+ headers: { ... },
485
+ status: 500 ,
486
+ body: ' ...'
487
+ }
488
+ }
489
+ ```
490
+
491
+ Note that yea throws regular synchronous errors if a request config is invalid, e.g.
492
+
493
+ ``` js
494
+ throw new Error (' Invalid header value for header \' ' + name + ' \' ' );
495
+ ```
Original file line number Diff line number Diff line change @@ -90,7 +90,11 @@ request
90
90
console .log (response .body );
91
91
})
92
92
.catch (error => {
93
- console .error (error .response .status );
93
+ if (error .response ) {
94
+ console .error (error .response .status );
95
+ } else {
96
+ // ...
97
+ }
94
98
})
95
99
96
100
// POST requests
You can’t perform that action at this time.
0 commit comments