To add onto this thread while we're discussing this flow, what would be the recommended way to handle issues with the Log::log_exception() call in these catch blocks? We had an instance where the client's security role in MSSQL wasn't correct, so when an exception was thrown it was caught but then tried to write to the log table, which failed and produced a 500 error. The code to write to the log table is pretty basic:
class Log
{
/**
* Logs an exception into the error log database table.
*
* @param Database_Interface $db The database object.
* @param Exception $e The Exception.
* @param string $user The shortname of the user.
*
* @return void
*/
public static function log_exception(Database_Interface $db, Exception $e, $user)
{
$query = " INSERT INTO
error_log (error_exception_type, error_exception_trace, error_exception_user_message, error_line, error_file, error_user)
VALUES (?, ?, ?, ?, ?, ?)";
$parameters = [
['s', get_class($e)],
['s', $e->getTraceAsString()],
['s', $e->getMessage()],
['s', $e->getLine()],
['s', $e->getFile()],
['s', $user],
];
$db->prepare($query)->bind_parameters($parameters)->execute(false);
}
}
I guess I could throw a try/catch around the database call and then just write to the error log? What about returning a message back to the user? I guess log_exception could return a boolean which could be evaluated? Would love to hear some thoughts on this.
Weedpacket;11053169 wrote:Well, nothing's stopping you from adding interfaces (as part of your refactoring, for instance).
Heh, very true :p. I haven't had much time to refactor as the client is pushing, pushing, pushing to move forward, so at this point I am picking and choosing my battles and just creating issues in the tracker to revisit later.