Replies: 3 comments 4 replies
-
On second thought, these would probably need a way to customize the exception thrown too, because the default exception used by |
Beta Was this translation helpful? Give feedback.
-
I would also love to see a streamlined way to not only use http status codes for determining if there is an error. Many API's out there don't (properly) report status codes and it's a pain. |
Beta Was this translation helpful? Give feedback.
-
I agree, this is a needed/wanted feature. I think this can be done via the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to see
thowIf()
andthrowUnless()
methods added to the HTTP Client.Sometimes you may find yourself (like me) using the HTTP Client to interact with an API that is not RESTful in its use of HTTP Status Codes. For example I am working with this one API that always returns a status code of 200, even in an error occurs and the only sign of an error is in the json response body.
throwIf()
would accept 2 closures. The first (required) would be a closure to determine if the request was unsuccessful and an error should be thrown. The closure would have the response object passed in to be inspected and would simply need to returnTrue
if the request should be considered failed. Thus if the closure returnsTrue
the exception would be thrown or otherwise it would not. The second closure (optional) would contain any code that should be ran prior to throwing the error, just as the closure inthrow()
does.throwUnless()
would be the logical opposite ofthrowIf()
, it would still receive the same two closures, but instead is testing if the request was successful, therefore it should throw the error unless the closure returnsTrue
confirming the request was successful.Beta Was this translation helpful? Give feedback.
All reactions