Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
Allow configurable exception_message (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanlaak authored and Gilles Gauthier committed Feb 14, 2018
1 parent d89f785 commit 696ed7c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
5 changes: 4 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public function getConfigTreeBuilder()
->defaultValue( 503 )
->end()
->scalarNode('status')
->defaultValue( "Service Temporarily Unavailable")
->defaultValue('Service Temporarily Unavailable')
->end()
->scalarNode('exception_message')
->defaultValue('Service Temporarily Unavailable')
->end()
->end()
->end()
Expand Down
6 changes: 3 additions & 3 deletions Exception/ServiceUnavailableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class ServiceUnavailableException extends HttpException
/**
* Constructor.
*
* @param string $message The internal exception message
* @param Exception $previous The previous exception
* @param integer $code The internal exception code
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param integer $code The internal exception code
*/
public function __construct($message = null, \Exception $previous = null, $code = 0)
{
Expand Down
12 changes: 9 additions & 3 deletions Listener/MaintenanceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class MaintenanceListener
*/
protected $http_status;

/**
* @var null|String
*/
protected $http_exception_message;

/**
* @var bool
*/
Expand Down Expand Up @@ -106,6 +111,7 @@ class MaintenanceListener
* @param array $attributes Attributes
* @param Int $http_code http status code for response
* @param String $http_status http status message for response
* @param null $http_exception_message http response page exception message
* @param bool $debug
*/
public function __construct(
Expand All @@ -119,6 +125,7 @@ public function __construct(
$attributes = array(),
$http_code = null,
$http_status = null,
$http_exception_message = null,
$debug = false
) {
$this->driverFactory = $driverFactory;
Expand All @@ -131,6 +138,7 @@ public function __construct(
$this->attributes = $attributes;
$this->http_code = $http_code;
$this->http_status = $http_status;
$this->http_exception_message = $http_exception_message;
$this->debug = $debug;
}

Expand Down Expand Up @@ -195,10 +203,8 @@ public function onKernelRequest(GetResponseEvent $event)

if ($driver->decide() && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$this->handleResponse = true;
throw new ServiceUnavailableException();
throw new ServiceUnavailableException($this->http_exception_message);
}

return;
}

/**
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<argument>%lexik_maintenance.authorized.attributes%</argument>
<argument>%lexik_maintenance.response.http_code%</argument>
<argument>%lexik_maintenance.response.http_status%</argument>
<argument>%lexik_maintenance.response.exception_message%</argument>
<argument>%kernel.debug%</argument>
</service>

Expand Down
9 changes: 5 additions & 4 deletions Resources/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ The ttl (time to life) option is optional everywhere, it is used to indicate the
class: 'Lexik\Bundle\MaintenanceBundle\Drivers\DatabaseDriver' # class for database driver

# Option 1 : for doctrine
options: {connection: custom} # Optional. You can choice an other connection. Without option it's the doctrine default connection who will be used
options: {connection: custom} # Optional. You can choice an other connection. Without option it's the doctrine default connection who will be used

# Option 2 : for dsn, you must have a column ttl type datetime in your table.
options: {dsn: "mysql:dbname=maintenance;host:localhost", table: maintenance, user: root, password: root} # the dsn configuration, name of table, user/password

#Optional. response code and status of the maintenance page
response:
code: 503
status: "Service Temporarily Unavailable"
code: 503 # Http response code of Exception page
status: "Service Temporarily Unavailable" # Exception page title
exception_message: "Service Temporarily Unavailable" # Message when Exception is thrown


### Commands
Expand Down Expand Up @@ -109,7 +110,7 @@ In the listener, an exception is thrown when web site is under maintenance. This

.. note::

You must remember that this only works if Symfony2 works.
You must remember that this only works if Symfony works.

----------------------

Expand Down

0 comments on commit 696ed7c

Please sign in to comment.