Skip to content

Commit 804614a

Browse files
feat: provide a helpful error message if no DB access
If unable to access the database provide a helpful error message. Now the error message will say: Unable to connect to the database. Ask the website administrator to verify that the database has been created/initialized. They should also verify that the config/config.php database configuration is correct. Previously it said: Unknown Error
1 parent c996aa5 commit 804614a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lang/en_us.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ protected function _LoadStrings()
9494
$strings['Error'] = 'Error';
9595
$strings['ReturnToPreviousPage'] = 'Return to the last page that you were on';
9696
$strings['UnknownError'] = 'Unknown Error';
97+
$strings['DatabaseConnectionError'] = 'Unable to connect to the database.<br/>Ask the website administrator to verify that the database has been created/initialized.<br/>They should also verify that the <code>config/config.php</code> database configuration is correct.';
9798
$strings['InsufficientPermissionsError'] = 'You do not have permission to access this resource';
9899
$strings['MissingReservationResourceError'] = 'A resource was not selected';
99100
$strings['MissingReservationScheduleError'] = 'A schedule was not selected';

lib/Common/ErrorMessages.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ErrorMessages
88
public const MISSING_SCHEDULE = 3;
99
public const RESERVATION_NOT_FOUND = 4;
1010
public const RESERVATION_NOT_AVAILABLE = 5;
11+
public const DATABASE_CONNECTION = 6;
1112

1213
private $_resourceKeys = [];
1314
private static $_instance;
@@ -19,6 +20,7 @@ private function __construct()
1920
$this->SetKey(ErrorMessages::MISSING_SCHEDULE, 'MissingReservationScheduleError');
2021
$this->SetKey(ErrorMessages::RESERVATION_NOT_FOUND, 'ReservationNotFoundError');
2122
$this->SetKey(ErrorMessages::RESERVATION_NOT_AVAILABLE, 'ReservationNotAvailable');
23+
$this->SetKey(ErrorMessages::DATABASE_CONNECTION, 'DatabaseConnectionError');
2224
}
2325

2426
/**

lib/Common/Logging/ExceptionHandler.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ public function HandleException($exception)
4242
ob_start();
4343
debug_print_backtrace();
4444
error_log(ob_get_clean());
45-
call_user_func($this->callback);
45+
$errorMessageId = ErrorMessages::UNKNOWN_ERROR;
46+
if (
47+
str_contains($exception->getMessage(), 'Error connecting to database')
48+
|| str_contains($exception->getMessage(), 'Error selecting database')
49+
) {
50+
$errorMessageId = ErrorMessages::DATABASE_CONNECTION;
51+
}
52+
53+
call_user_func($this->callback, $errorMessageId);
4654
}
4755
}
4856

0 commit comments

Comments
 (0)