From 313d22ffcacab76723c7105a5bf46b48e1b738a4 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 7 Sep 2018 11:03:51 +0200 Subject: [PATCH] FIX Only continue delegation when DB exceptions are caused by no database selected This prevents the middleware from interrupting legitimate database exceptions from being propagated. --- src/Middleware/InitStateMiddleware.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Middleware/InitStateMiddleware.php b/src/Middleware/InitStateMiddleware.php index b5abf0c..4b7cd30 100644 --- a/src/Middleware/InitStateMiddleware.php +++ b/src/Middleware/InitStateMiddleware.php @@ -43,8 +43,12 @@ class InitStateMiddleware implements HTTPMiddleware return $delegate($request); } catch (DatabaseException $ex) { - // Database is not ready - return $delegate($request); + $message = $ex->getMessage(); + if (strpos($message, 'No database selected') !== false) { + // Database is not ready, ignore and continue + return $delegate($request); + } + throw $ex; } finally { // Persist to the session if using the CMS if ($state->getUseSessions()) {