Using the error middleware always trigger an error: "the service "@provider" does not exist"

Hi, I'd like to ask for some help with using the error middleware with Traefik 3.7.5 on Docker. I'm getting an error which looks unrelated and I'm not sure if it's a configuration issue or a bug.

I'm trying to create an error middleware rewriting 403 to 500 but always get an unrelated error the service "@provider" does not exist when using it.

In the file provider:

    local_ip:
      IPAllowList:
        sourceRange:
          - 127.0.0.1/32
          - 10.0.0.0/8
          - 172.16.0.0/12
          - 192.168.0.0/16

    rewrite_status:
      errors:
        statusRewrites:
          "403": 500
  
    local_only:
      chain:
        middlewares:
          - rewrite_status
          - local_ip

In the docker compose:

    labels:
      - traefik.enable=true
      - traefik.http.routers.test.rule=Host(`test.com`)
      - traefik.http.routers.test.middlewares=local_only@file

Also tried using docker labels:

    labels:
      - traefik.enable=true
      - traefik.http.routers.test.rule=Host(`test.com`)
      - traefik.http.middlewares.rewrite_stat.errors.statusRewrites.403=500
      - traefik.http.routers.test.middlewares=test_mw
      - traefik.http.middlewares.test_mw.chain.middlewares=local_ip@file,rewrite_stat

The local_ip@file middleware on its own works well. It allows to quickly test from a mobile connection.

Accessing test.com gives a 404.

On the traefik dashboard, the error middleware shows an error:

  • the service "@file" does not exist when using the file provider (local_only@file)
  • the service "@docker" does not exist when using docker labels (test_mw)

Image

When the middleware is not used in a chain or a label, it shows up in the dashboard with no error.

The error message is really puzzling as the providers do exist and work which does not help me identify what the issue could be here.

Hi, did you find a solution?

I found the solution. The errors middleware requires a service to work

The errors middleware requires a service field, not just statusRewrites. That empty service is why Traefik com@providerlains about "@provider" not existing, it's trying to resolve a blank service name against the provider. The errors middleware needs to point at a backend service that serves your custom error page. Add a service key pointing to a defined service and the resolution error should clear.

Oh, thanks for looking into that! I'll try and test that later.

So it might not be a bug but a documentation issue as the configuration options of the errors middleware list service as not required.

There's one thing that is puzzling me though: Traefik can already display errors, so why does it need another service to display them here? My goal is to only change the http status code in certain circumstances, not display fancy error pages so if possible, I'd like to avoid adding another service.

After further research on the topic it seems that there is a plugin for this and that describe my use case.

"Some apps become unhappy when they receive unexpected error codes, such as when Traefik can't find an available server.
This plugin solves this issue by filtering and replacing problematic error codes with ones the app won't complain about."