You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fix: response error interceptor broken
Expose the interceptor in the same manner as the others.
Remove `throwOnError` as it is considered an invalid argument.
* cleanup
* docs
---------
Co-authored-by: Matteo Collina <hello@matteocollina.com>
The `responseError` interceptor throws an error for responses with status code errors (>= 400).
1060
1060
1061
-
The Response Error Interceptor is designed to handle HTTP response errors efficiently. It intercepts responses and throws detailed errors for responses with status codes indicating failure (4xx, 5xx). This interceptor enhances error handling by providing structured error information, including response headers, data, and status codes.
1062
-
1063
-
**ResponseError Class**
1064
-
1065
-
The `ResponseError` class extends the `UndiciError` class and encapsulates detailed error information. It captures the response status code, headers, and data, providing a structured way to handle errors.
1066
-
1067
-
**Definition**
1068
-
1069
-
```js
1070
-
classResponseErrorextendsUndiciError {
1071
-
constructor (message, code, { headers, data }) {
1072
-
super(message);
1073
-
this.name='ResponseError';
1074
-
this.message= message ||'Response error';
1075
-
this.code='UND_ERR_RESPONSE';
1076
-
this.statusCode= code;
1077
-
this.data= data;
1078
-
this.headers= headers;
1079
-
}
1080
-
}
1081
-
```
1082
-
1083
-
**Interceptor Handler**
1084
-
1085
-
The interceptor's handler class extends `DecoratorHandler` and overrides methods to capture response details and handle errors based on the response status code.
1086
-
1087
-
**Methods**
1088
-
1089
-
-**onConnect**: Initializes response properties.
1090
-
-**onHeaders**: Captures headers and status code. Decodes body if content type is `application/json` or `text/plain`.
1091
-
-**onData**: Appends chunks to the body if status code indicates an error.
1092
-
-**onComplete**: Finalizes error handling, constructs a `ResponseError`, and invokes the `onError` method.
// Will throw a ResponseError for status codes >= 400
1072
+
awaitclient.request({
1073
+
method:"GET",
1074
+
path:"/"
1247
1075
});
1248
1076
```
1249
1077
1250
-
**Conclusion**
1251
-
1252
-
The Response Error Interceptor provides a robust mechanism for handling HTTP response errors by capturing detailed error information and propagating it through a structured `ResponseError` class. This enhancement improves error handling and debugging capabilities in applications using the interceptor.
1253
-
1254
1078
##### `Cache Interceptor`
1255
1079
1256
1080
The `cache` interceptor implements client-side response caching as described in
0 commit comments