Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EG should allow developer to define errors in Proxy Policy #692

Open
djesani opened this issue Apr 13, 2018 · 4 comments
Open

EG should allow developer to define errors in Proxy Policy #692

djesani opened this issue Apr 13, 2018 · 4 comments
Assignees

Comments

@djesani
Copy link

djesani commented Apr 13, 2018

At the moment, if a request is unauthorized or a service endpoint becomes unavailable, EG simply returns plain text responses, such as "UNAUTHORIZED" or "BAD GATEWAY".

EG should allow the developer to decide how the error is returned, for example a JSON response or a HTML response and gracefully fallback to the plain text errors if these are not defined by the developer.

@XVincentX XVincentX changed the title EG should allow developer to define errors EG should allow developer to define errors in Proxy Policy Apr 15, 2018
@XVincentX
Copy link
Member

The error handler is here

Not to sure how we can implement a declarative yet flexible error handler.

@dyrkow
Copy link

dyrkow commented Sep 14, 2018

@XVincentX Hi, I had the same problem.

I need to always return the JSON.

How can I send an error (JSON obj) if not one condition.pattern does not match?

....

pipelines:

  api:
    apiEndpoints:
      - base
    policies:
      - proxy:

          - condition:
              name: pathMatch
              pattern: '/serviecName/*'
            action:
              serviceEndpoint: someService

          - condition:
              name: pathMatch
              pattern: '/serviceName/*'
            action:
              serviceEndpoint: someService

@XVincentX
Copy link
Member

@WebWorkDeveloper Your issue is not really connected to this one. This one is about customizing proxy errors — you just want to return a JSON payload in case something goes wrong.

We do not have a direct way to do that right now; you can use the expression policy to execute a small javascript code which can return the response you need.

@gmauricio
Copy link

@XVincentX I'm probably missing something but how would you use an expression to do this ? If I understand correctly there's no way to have access to the proxy error or proxied response out of the proxy policy implementation.
I've seen some gateways have a way to specify an "error page", for example: https://docs.traefik.io/middlewares/errorpages/#configuration-options.
They require you to host the "error page" but that might not be required in this case. I think the proxy could add an option to pass an errorMessage. Alternatively, is it possible to have an "errorAction" ? that might be more flexible, because you could use it to override status code and headers as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants