-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
interceptors: move throwOnError to interceptor #3331
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove http-errors
Co-authored-by: Robert Nagy <ronagy@icloud.com>
Co-authored-by: Robert Nagy <ronagy@icloud.com>
Co-authored-by: Robert Nagy <ronagy@icloud.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not forget to add docs and TS types 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also apply it to one of the API decoreators?
e.g.
diff --git a/lib/api/api-request.js b/lib/api/api-request.js
index ced5590d..f91b830a 100644
--- a/lib/api/api-request.js
+++ b/lib/api/api-request.js
@@ -13,7 +13,7 @@ class RequestHandler extends AsyncResource {
throw new InvalidArgumentError('invalid opts')
}
- const { signal, method, opaque, body, onInfo, responseHeaders, throwOnError, highWaterMark } = opts
+ const { signal, method, opaque, body, onInfo, responseHeaders, highWaterMark } = opts
try {
if (typeof callback !== 'function') {
@@ -54,7 +54,6 @@ class RequestHandler extends AsyncResource {
this.trailers = {}
this.context = null
this.onInfo = onInfo || null
- this.throwOnError = throwOnError
this.highWaterMark = highWaterMark
this.signal = signal
this.reason = null
@@ -132,20 +131,14 @@ class RequestHandler extends AsyncResource {
this.callback = null
this.res = res
if (callback !== null) {
- if (this.throwOnError && statusCode >= 400) {
- this.runInAsyncScope(getResolveErrorBodyCallback, null,
- { callback, body: res, contentType, statusCode, statusMessage, headers }
- )
- } else {
- this.runInAsyncScope(callback, null, null, {
- statusCode,
- headers,
- trailers: this.trailers,
- opaque,
- body: res,
- context
- })
- }
+ this.runInAsyncScope(callback, null, null, {
+ statusCode,
+ headers,
+ trailers: this.trailers,
+ opaque,
+ body: res,
+ context
+ })
}
}
@@ -200,7 +193,7 @@ function request (opts, callback) {
}
try {
- this.dispatch(opts, new RequestHandler(opts, callback))
+ this.compose(responseErrorInterceptor()).dispatch(opts, new RequestHandler(opts, callback))
} catch (err) {
if (typeof callback !== 'function') {
throw err
Co-authored-by: Robert Nagy <ronagy@icloud.com>
Co-authored-by: Robert Nagy <ronagy@icloud.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests seems to be failing
Solved 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add the respective TS types and docs 👍
Which md file should I put the doc in, do you have any suggestions? |
Within |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It LGTM, just smaller comments on the docs 👍
Co-authored-by: Khafra <maitken033380023@gmail.com>
(cherry picked from commit 0ea1074)
Test Issue:
Need assistance to resolve test failures.