Home About News Products Blog

How to test custom error pages


#1

A user asks:

I’ve setup custom error pages for 502 and 504 errors as per your documentation here: https://www.section.io/docs/reference/http-error-messages/#custom-error-messages
How do I test them?

We recommend setting up a custom URL in Varnish that generates a synthetic response that has the status code of the error page you are testing.

For Varnish 3.x this would look like.

sub vcl_recv {
    if (req.url ~ "^/section_error_502.html") {
        error 502 "Test error 502";
    }
}

Or in Varnish 4.x or higher.

if (req.url ~ "^/section_error_502.html") {
    return(synth(502, "Test error 502"));
} 

If you have lots of error codes you would like to test, then the following VCL 4.0 may be helpful instead of having an IF statement for each error.

import std;
if (req.url ~ "^/section_error_[4-5][0-9]{2}.html") {
    set req.http.section-error-code = regsub(req.url, "/section_error_([0-9]{3}).html", "\1");
    return(synth(std.integer(req.http.section-error-code, 0), "Test error"));
}