Skip to content

Commit 8116e4d

Browse files
committed
Added Response status validation.
1 parent 46aab5e commit 8116e4d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/tools/MessageHelper.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use InvalidArgumentException;
99
use Psr\Http\Message\MessageInterface;
1010
use Psr\Http\Message\RequestInterface;
11+
use Psr\Http\Message\ResponseInterface;
1112

1213
class MessageHelper
1314
{
@@ -142,6 +143,31 @@ public static function withContent(MessageInterface $message, string $mediaType,
142143
->withBody($body)
143144
->withHeader('Content-Type', $mediaType);
144145
}
146+
147+
public static function isInfo(ResponseInterface $response) : bool
148+
{
149+
return $response->getStatusCode() >= 100 && $response->getStatusCode() < 200;
150+
}
151+
public static function isSuccess(ResponseInterface $response) : bool
152+
{
153+
return $response->getStatusCode() >= 200 && $response->getStatusCode() < 300;
154+
}
155+
public static function isRedirect(ResponseInterface $response) : bool
156+
{
157+
return $response->getStatusCode() >= 300 && $response->getStatusCode() < 400;
158+
}
159+
public static function isClientError(ResponseInterface $response) : bool
160+
{
161+
return $response->getStatusCode() >= 400 && $response->getStatusCode() < 500;
162+
}
163+
public static function isServerError(ResponseInterface $response) : bool
164+
{
165+
return $response->getStatusCode() >= 500;
166+
}
167+
public static function isError(ResponseInterface $response) : bool
168+
{
169+
return $response->getStatusCode() >= 400;
170+
}
145171
}
146172

147173
MessageHelper::setAuthenticationSchemes(array(

0 commit comments

Comments
 (0)