Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HttpKernel] normalized HTTP exceptions classes #5862

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class AccessDeniedHttpException extends HttpException
*
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param integer $code The internal exception code
* @param array $headers An array of HTTP headers
*/
public function __construct($message = null, \Exception $previous = null, $code = 0)
public function __construct($message = null, \Exception $previous = null, array $headers = array())
{
parent::__construct(403, $message, $previous, array(), $code);
parent::__construct(403, $message, $previous, $headers);
}
}
18 changes: 16 additions & 2 deletions src/Symfony/Component/HttpKernel/Exception/HttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,33 @@ class HttpException extends \RuntimeException implements HttpExceptionInterface
private $statusCode;
private $headers;

public function __construct($statusCode, $message = null, \Exception $previous = null, array $headers = array(), $code = 0)
/**
* Constructor.
*
* @param integer $statusCode The HTTP status code
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param array $headers An array of HTTP headers
*/
public function __construct($statusCode, $message = null, \Exception $previous = null, array $headers = array())
{
$this->statusCode = $statusCode;
$this->headers = $headers;

parent::__construct($message, $code, $previous);
parent::__construct($message, 0, $previous);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep it? I find it quite nice that generic exception handlers can read out the code and get useful info out of it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, this is always 0.

Also, the list of arguments for the constructors is already quite long, so added something that is never used makes little sense to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I meant why not use $statusCode in there then?

}

/**
* {@inheritdoc}
*/
public function getStatusCode()
{
return $this->statusCode;
}

/**
* {@inheritdoc}
*/
public function getHeaders()
{
return $this->headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class MethodNotAllowedHttpException extends HttpException
* @param array $allow An array of allowed methods
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param integer $code The internal exception code
* @param array $headers An array of HTTP headers
*/
public function __construct(array $allow, $message = null, \Exception $previous = null, $code = 0)
public function __construct(array $allow, $message = null, \Exception $previous = null, array $headers = array())
{
$headers = array('Allow' => strtoupper(implode(', ', $allow)));
$headers = array_merge($headers, array('Allow' => strtoupper(implode(', ', $allow))));

parent::__construct(405, $message, $previous, $headers, $code);
parent::__construct(405, $message, $previous, $headers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class NotFoundHttpException extends HttpException
*
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param integer $code The internal exception code
* @param array $headers An array of HTTP headers
*/
public function __construct($message = null, \Exception $previous = null, $code = 0)
public function __construct($message = null, \Exception $previous = null, array $headers = array())
{
parent::__construct(404, $message, $previous, array(), $code);
parent::__construct(404, $message, $previous, $headers);
}
}