Skip to content

Commit

Permalink
catch database error
Browse files Browse the repository at this point in the history
  • Loading branch information
alexweissman committed Dec 3, 2016
1 parent 2dcad08 commit a1a96fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion app/sprinkles/account/src/Authenticate/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,17 @@ public function __construct(ClassMapper $classMapper, Session $session, $config)

// Initialize RememberMe storage
$this->rememberMeStorage = new RememberMePDO($this->config['remember_me.table']);
$this->rememberMeStorage->setConnection(Capsule::connection()->getPdo());

// Catch the BindingResolutionException if we can't connect to the DB
try {
$pdo = Capsule::connection()->getPdo();
} catch (\Illuminate\Contracts\Container\BindingResolutionException $e) {
$dbParams = $config['db'];
throw new \PDOException("Could not connect to the database '{$dbParams['username']}@{$dbParams['host']}/{$dbParams['database']}'. Please check your database configuration.");
}

$this->rememberMeStorage->setConnection($pdo);

// Set up RememberMe
$this->rememberMe = new RememberMe($this->rememberMeStorage);
// Set cookie name
Expand Down
4 changes: 2 additions & 2 deletions app/sprinkles/core/src/Handler/CoreErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function __construct(ContainerInterface $ci, $displayErrorDetails = false
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, \Exception $exception)
{
// If displayErrorDetails is set to true, render a debugging error page
if ($this->displayErrorDetails) {
// If displayErrorDetails is set to true, and we're not processing an AJAX request with AJAX debug mode turned off, render a debugging error page
if ($this->displayErrorDetails && (!$request->isXhr() || $this->ci->config['site.debug.ajax'])) {
return $this->getDebugResponse($request, $response, $exception);
}

Expand Down

0 comments on commit a1a96fa

Please sign in to comment.