Commit e71d749e authored by alexpott's avatar alexpott

Issue #2194111 by sun: Error handler throws exception when service container...

Issue #2194111 by sun: Error handler throws exception when service container is not (fully) available yet.
parent e17552ab
......@@ -1300,7 +1300,7 @@ function watchdog($type, $message, array $variables = NULL, $severity = WATCHDOG
// It is possible that the error handling will itself trigger an error. In that case, we could
// end up in an infinite loop. To avoid that, we implement a simple static semaphore.
if (!$in_error_state && function_exists('module_implements')) {
if (!$in_error_state && \Drupal::hasService('module_handler')) {
$in_error_state = TRUE;
// The user object may not exist in all conditions, so 0 is substituted if needed.
......
......@@ -169,7 +169,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
}
}
if (\Drupal::request()->isXmlHttpRequest()) {
if (\Drupal::hasRequest() && \Drupal::request()->isXmlHttpRequest()) {
if ($fatal) {
if (error_displayable($error)) {
// When called from JavaScript, simply output the error message.
......
......@@ -149,6 +149,16 @@ public static function hasService($id) {
return static::$container && static::$container->has($id);
}
/**
* Indicates if there is a currently active request object.
*
* @return bool
* TRUE if there is a currently active request object, FALSE otherwise.
*/
public static function hasRequest() {
return static::$container && static::$container->has('request') && static::$container->initialized('request') && static::$container->isScopeActive('request');
}
/**
* Retrieves the currently active request object.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment