Errors

It Has Never Been Easier to Say That Something Went Wrong

Errors

The Errors middleware returns a custom page in lieu of the default, according to configured ranges of HTTP Status codes.

Important

The error page itself is not hosted by Traefik.

Configuration Examples

Docker

  1. # Dynamic Custom Error Page for 5XX Status Code
  2. labels:
  3. - "traefik.http.middlewares.test-errors.errors.status=500,501,503,505-599"
  4. - "traefik.http.middlewares.test-errors.errors.service=serviceError"
  5. - "traefik.http.middlewares.test-errors.errors.query=/{status}.html"

Kubernetes

  1. apiVersion: traefik.io/v1alpha1
  2. kind: Middleware
  3. metadata:
  4. name: test-errors
  5. spec:
  6. errors:
  7. status:
  8. - "500"
  9. - "501"
  10. - "503"
  11. - "505-599"
  12. query: /{status}.html
  13. service:
  14. name: whoami
  15. port: 80

Consul Catalog

  1. # Dynamic Custom Error Page for 5XX Status Code excluding 502 and 504
  2. - "traefik.http.middlewares.test-errors.errors.status=500,501,503,505-599"
  3. - "traefik.http.middlewares.test-errors.errors.service=serviceError"
  4. - "traefik.http.middlewares.test-errors.errors.query=/{status}.html"

Marathon

  1. "labels": {
  2. "traefik.http.middlewares.test-errors.errors.status": "500,501,503,505-599",
  3. "traefik.http.middlewares.test-errors.errors.service": "serviceError",
  4. "traefik.http.middlewares.test-errors.errors.query": "/{status}.html"
  5. }

Rancher

  1. # Dynamic Custom Error Page for 5XX Status Code excluding 502 and 504
  2. labels:
  3. - "traefik.http.middlewares.test-errors.errors.status=500,501,503,505-599"
  4. - "traefik.http.middlewares.test-errors.errors.service=serviceError"
  5. - "traefik.http.middlewares.test-errors.errors.query=/{status}.html"

File (YAML)

  1. # Dynamic Custom Error Page for 5XX Status Code excluding 502 and 504
  2. http:
  3. middlewares:
  4. test-errors:
  5. errors:
  6. status:
  7. - "500"
  8. - "501"
  9. - "503"
  10. - "505-599"
  11. service: serviceError
  12. query: "/{status}.html"
  13. services:
  14. # ... definition of error-handler-service and my-service

File (TOML)

  1. # Dynamic Custom Error Page for 5XX Status Code excluding 502 and 504
  2. [http.middlewares]
  3. [http.middlewares.test-errors.errors]
  4. status = ["500","501","503","505-599"]
  5. service = "serviceError"
  6. query = "/{status}.html"
  7. [http.services]
  8. # ... definition of error-handler-service and my-service

In this example, the error page URL is based on the status code (query=/{status}.html).

Configuration Options

status

The status option defines which status or range of statuses should result in an error page.

The status code ranges are inclusive (505-599 will trigger with every code between 505 and 599, 505 and 599 included).

You can define either a status code as a number (500), as multiple comma-separated numbers (500,502), as ranges by separating two codes with a dash (505-599), or a combination of the two (404,418,505-599). The comma-separated syntax is only available for label-based providers. The examples above demonstrate which syntax is appropriate for each provider.

service

The service that will serve the new requested error page.

In Kubernetes, you need to reference a Kubernetes Service instead of a Traefik service.

Host Header

By default, the client Host header value is forwarded to the configured error service. To forward the Host value corresponding to the configured error service URL, the passHostHeader option must be set to false.

query

The URL for the error page (hosted by service)).

There are multiple variables that can be placed in the query option to insert values in the URL.

The table below lists all the available variables and their associated values.

VariableValue
{status}The response status code.
{url}The escaped request URL.