From 1e4c57c50c1eeecd7557504e80ca41f2e617e241 Mon Sep 17 00:00:00 2001 From: Ahmad Mayahi Date: Fri, 8 Oct 2021 15:48:38 +0200 Subject: [PATCH] [8.x] Add throwIf method in Client Response (#39148) * Add throwIf * Update Response.php * Update Response.php * Update Response.php * Update Response.php Co-authored-by: Taylor Otwell --- src/Illuminate/Http/Client/Response.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Illuminate/Http/Client/Response.php b/src/Illuminate/Http/Client/Response.php index 84ba0bd56c98..08373fbc500a 100644 --- a/src/Illuminate/Http/Client/Response.php +++ b/src/Illuminate/Http/Client/Response.php @@ -282,6 +282,19 @@ public function throw() return $this; } + /** + * Throw an exception if a server or client error occurred and the given condition evaluates to true. + * + * @param bool $condition + * @return $this + * + * @throws \Illuminate\Http\Client\RequestException + */ + public function throwIf($condition) + { + return $condition ? $this->throw() : $this; + } + /** * Determine if the given offset exists. *