[9.x] Added 'throw' method to PendingRequest #41953
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey! This PR proposes a new
throw
method that can be added to thePendingRequest
class for using on theHTTP
facade.In one of my projects, I have a "base client" (for lack of a better term) that I use when making requests to an API. It looks something like this:
And then I want to make any requests, I can call it like so:
I use the "base client" in quite a few different places with different API routes and noticed that I'd forgotten to add
throw()
to one of my requests, so a small bug was slipping through. Of course, this is something that my tests should have picked up on, but I think I missed this particular edge case.So, this PR allows you to add
throw
to yourPendingRequest
so that we don't need to remember to place it on the individual responses. For example, I could update my code to this instead:and then remove
throw
from the response:Now, this means that if there's a client error or server error when using my "base client", it means that an exception will always be thrown.
From what I can see, this appears to be working and I've tried to keep it working the same as the
throw
method on theResponse
, but it's possible that I might have missed something off.If it's something that you think might be useful to other devs, please let me know if there's anything you might want changing 😄