[7.x] Add a base exception for Http exceptions #33581
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.
I suggest that we add a base exception that the exceptions thrown by the Http client can extend.
By doing that it's easy to catch any errors that will be thrown.
Here is a real-life Stripe portal integration before and after.
Before
After
This is a very simple addition which will not be a breaking change, as people can still catch the individual exceptions or the \Exception class.
I'm open to other names for the base exceptions.
I've called it "HttpClientException", but other names could be:
You could argue that we can just catch the \Exception class, but I don't want to do that in case that any exceptions are thrown by some other logic in the try-catch block. This could e.g. be an exception thrown by
$client->stripe_customer_id