Commit 06d920a0 authored by alexpott's avatar alexpott

Issue #2429671 by Berdir, Wim Leers: "The website has encountered an error....

Issue #2429671 by Berdir, Wim Leers: "The website has encountered an error. Please try again later." page is cached
parent ae4848f5
......@@ -140,6 +140,11 @@ services:
class: Drupal\Core\PageCache\ResponsePolicy\KillSwitch
tags:
- { name: page_cache_response_policy }
page_cache_no_server_error:
class: Drupal\Core\PageCache\ResponsePolicy\NoServerError
public: false
tags:
- { name: page_cache_response_policy }
config.manager:
class: Drupal\Core\Config\ConfigManager
arguments: ['@entity.manager', '@config.factory', '@config.typed', '@string_translation', '@config.storage', '@event_dispatcher']
......
<?php
/**
* @file
* Contains \Drupal\Core\PageCache\ResponsePolicy\NoServerError.
*/
namespace Drupal\Core\PageCache\ResponsePolicy;
use Drupal\Core\PageCache\ResponsePolicyInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* A policy denying caching of a server error (HTTP 5xx) responses.
*/
class NoServerError implements ResponsePolicyInterface {
/**
* {@inheritdoc}
*/
public function check(Response $response, Request $request) {
if ($response->isServerError()) {
return static::DENY;
}
}
}
......@@ -130,6 +130,22 @@ function testExceptionHandler() {
$this->assertTrue(strpos($this->drupalGetHeader(':status'), '500 Service unavailable (with message)'), 'Received expected HTTP status line.');
$this->assertErrorMessage($error_renderer_exception);
// Enable the page cache and disable error reporting, ensure that 5xx
// responses are not cached.
$config = $this->config('system.performance');
$config->set('cache.page.use_internal', 1);
$config->set('cache.page.max_age', 300);
$config->save();
$this->config('system.logging')
->set('error_level', ERROR_REPORTING_HIDE)
->save();
$this->drupalGet('error-test/trigger-exception');
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'Received expected HTTP status line.');
$this->assertTrue(strpos($this->drupalGetHeader(':status'), '500 Service unavailable (with message)'), 'Received expected HTTP status line.');
$this->assertNoErrorMessage($error_exception);
// The exceptions are expected. Do not interpret them as a test failure.
// Not using File API; a potential error must trigger a PHP warning.
unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
......
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