Skip to content

Conversation

mertcanaltin
Copy link
Member

  • Moved throwOnError handling to response-error interceptor.
  • Updated retry tests to handle 400 status code properly.

Test Issue:

  • Encountered 'BadRequestError' (status 400) in 'should not error if request is not meant to be retried' test.

Need assistance to resolve test failures.

Copy link
Member

@KhafraDev KhafraDev left a 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 <[email protected]>
Co-authored-by: Robert Nagy <[email protected]>
@mertcanaltin mertcanaltin requested a review from ronag June 17, 2024 12:00
Copy link
Member

@metcoder95 metcoder95 left a 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 👍

Copy link
Member

@ronag ronag left a 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 <[email protected]>
Copy link
Member

@metcoder95 metcoder95 left a 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

@mertcanaltin
Copy link
Member Author

Tests seems to be failing

Solved 🚀

@mertcanaltin mertcanaltin requested a review from metcoder95 July 8, 2024 18:08
Copy link
Member

@metcoder95 metcoder95 left a 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 👍

@mertcanaltin
Copy link
Member Author

Let's add the respective TS types and docs 👍

Which md file should I put the doc in, do you have any suggestions?

@metcoder95
Copy link
Member

Which md file should I put the doc in, do you have any suggestions?

Within Dispatcher.md, there's a section there for interceptors that outlines the built-in ones 👍

Copy link
Member

@metcoder95 metcoder95 left a 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 👍

@mertcanaltin mertcanaltin requested a review from metcoder95 July 11, 2024 08:03
@mertcanaltin mertcanaltin added the interceptors Pull requests or issues related to Dispatcher Interceptors label Jul 11, 2024
@ronag ronag merged commit 0ea1074 into nodejs:main Jul 11, 2024
github-actions bot pushed a commit that referenced this pull request Sep 12, 2024
@github-actions github-actions bot mentioned this pull request Dec 3, 2024
This was referenced Dec 16, 2024
@github-actions github-actions bot mentioned this pull request Mar 12, 2025
@github-actions github-actions bot mentioned this pull request May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport v6.x interceptors Pull requests or issues related to Dispatcher Interceptors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants