Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[HttpKernel] Use a simple isError from Response for HandleException #7574

Closed
wants to merge 1 commit into from

2 participants

@ruian
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? no (but they did not pass at all)
License MIT
@fabpot
Owner

We already quite a lot of methods in this class, so adding yet another one (which is probably not that useful anyway) is not a good idea.

@fabpot fabpot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
12 src/Symfony/Component/HttpFoundation/Response.php
@@ -1119,6 +1119,18 @@ public function isServerError()
}
/**
+ * Was there a server or client side error?
+ *
+ * @return Boolean
+ *
+ * @api
+ */
+ public function isError()
+ {
+ return $this->statusCode >= 400 && $this->statusCode < 600;
+ }
+
+ /**
* Is the response OK?
*
* @return Boolean
View
9 src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php
@@ -664,6 +664,15 @@ public function testIsOk()
$this->assertFalse($response->isOk());
}
+ public function testIsError()
+ {
+ $response = new Response('', 404);
+ $this->assertTrue($response->isError());
+
+ $response = new Response('', 500);
+ $this->assertTrue($response->isError());
+ }
+
public function testIsServerOrClientError()
{
$response = new Response('', 404);
View
2  src/Symfony/Component/HttpKernel/HttpKernel.php
@@ -201,7 +201,7 @@ private function handleException(\Exception $e, $request, $type)
$response->setStatusCode($response->headers->get('X-Status-Code'));
$response->headers->remove('X-Status-Code');
- } elseif (!$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) {
+ } elseif (!$response->isError() && !$response->isRedirect()) {
// ensure that we actually have an error response
if ($e instanceof HttpExceptionInterface) {
// keep the HTTP status code and headers
Something went wrong with that request. Please try again.