forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add StackPHP and a basic Exception catching middleware
- Loading branch information
1 parent
55d0d60
commit 2458814
Showing
5 changed files
with
172 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Mautic\Middleware; | ||
|
||
use Mautic\CoreBundle\Exception\DatabaseConnectionException; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
|
||
class CatchExceptionMiddleware implements HttpKernelInterface | ||
{ | ||
/** | ||
* @var HttpKernelInterface | ||
*/ | ||
protected $app; | ||
|
||
/** | ||
* CatchExceptionMiddleware constructor. | ||
* | ||
* @param HttpKernelInterface $app | ||
*/ | ||
public function __construct(HttpKernelInterface $app) | ||
{ | ||
$this->app = $app; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) | ||
{ | ||
try { | ||
$response = $this->app->handle($request, $type, $catch); | ||
|
||
if ($response instanceof Response) { | ||
return $response; | ||
} | ||
} catch (DatabaseConnectionException $e) { | ||
define('MAUTIC_OFFLINE', 1); | ||
$message = $e->getMessage(); | ||
} catch (\Exception $e) { | ||
error_log($e); | ||
define('MAUTIC_OFFLINE', 1); | ||
$message = 'The site is currently offline due to encountering an error. If the problem persists, please contact the system administrator.'; | ||
$submessage = 'System administrators, check server logs for errors.'; | ||
} | ||
|
||
include MAUTIC_ROOT_DIR . '/offline.php'; | ||
exit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters