Skip to content

Commit

Permalink
Ensure custom errors are served for GOV.UK Chat
Browse files Browse the repository at this point in the history
We've added custom error pages for our 500 and 503 errors. This updates
the vcl_error subroutine to serve these custom error pages when the
'Govuk-Rendered-Error' header is set.

Our application returns a 503 status code when public access is toggled
off. I'm unsure if there are other cases where we may receive a 503
status code and Roch thinks that the load balancer will return a 500 status
if the application is down.

To ensure that we don't accidentally move to the deliver subroutine when
a 500 or 503 is returned without our custom error page we came up with the
idea of adding a header which indicates that we want to serve the page
from the application.

This change adds a check for the 'Govuk-Rendered-Error' header in the
vcl_error subroutine. If present it moves to the deliver subroutine
to serve the custom error page.
  • Loading branch information
davidgisbey committed Sep 18, 2024
1 parent 816dc4b commit e899d32
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion www/www.vcl.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ sub vcl_recv {
if (req.method !~ "^(GET|HEAD|POST|PUT|DELETE|OPTIONS|PATCH|FASTLYPURGE)") {
error 806 "Not Implemented";
}

%{ if private_extra_vcl_recv != "" ~}
${private_extra_vcl_recv}
%{ endif ~}
Expand Down Expand Up @@ -676,6 +676,10 @@ sub vcl_error {
}
}
if (beresp.http.Govuk-Rendered-Error) {
return (deliver);
}
# Assume we've hit vcl_error() because the backend is unavailable
# for the first two retries. By restarting, vcl_recv() will try
# serving from stale before failing over to the mirrors.
Expand Down

0 comments on commit e899d32

Please sign in to comment.