Fastly allows to customise vcl_error subroutine. However, If I override it (e.g.
sub vcl_error {
#FASTLY error
set obj.http.Custom-Header = "foo-bar";
return(deliver);
}
), original response body with error cause (e.g. "first byte timout") is lost.
Is it possible to obtain a cause, so I can add it to additional some header or syntetic body
The
vcl_errorsubroutine is triggered either implicitly by Fastly (see the documentation for examples of when it does this) or explicitly using theerrorstatement.Within
vcl_errortheobj.statusandobj.responsevariables provide information about the nature of the error.If you're explicitly triggering
vcl_error, then from within the subroutine you're invoking theerrorstatement you should set a custom HTTP header on an object that you can read back from withinvcl_error.For example, the
reqobject is available to all subroutines so you could usereq.http.{NAME}) to store off any contextual error information you want to use as part of your synthetic error response.One caveat with persisting data in this fashion is that you can't persist data across certain boundaries, such as the move from a subroutine on a 'fetching node' to a 'delivery node' (see clustering for details of what the difference between fetching/delivery nodes).
Off the top of my head (see also: https://www.integralist.co.uk/posts/fastly-varnish/#breadcrumb-trail) I believe if you're invoking
errorfromvcl_fetchyou'll need to persist the data to theberespobject and notreq. Varnish will copyberespto theobjobject that is exposed to thevcl_errorsubroutine.If you have any other questions or concerns, then please reach out to [email protected] who will be happy to help.
Please also refer to the Fastly 'Developer Hub' which has a bunch of resources on Varnish and VCL that might be useful to you.