<@U04UQ68083H> is there a way to define different ...
# ory-copilot
b
@chilly-king-10285 is there a way to define different redirects paths in an error handler for different "when" conditions?
c
A message from kapa.ai
New message text here
b
@chilly-king-10285 create an error handler for oathkeeper that will redirect to webpageA when the error is 401 and to webpageB when the error is 403
c
A message from kapa.ai
To create an error handler in Ory Oathkeeper that redirects to different web pages based on the error code (401 for unauthorized and 403 for forbidden), you can use the following configuration snippet. This configuration uses the
redirect
error handler and specifies different
when
conditions for the 401 and 403 HTTP status codes. Note that in Ory Oathkeeper's configuration, error names are derived from HTTP status messages, with lowercase and underscores. Therefore,
unauthorized
corresponds to a 401 error, and
forbidden
corresponds to a 403 error.
Copy code
yaml # .oathkeeper.yaml   errors:    handlers:    redirect:    enabled: true    config:    when:    - error:    - unauthorized    # Redirect path for 401 Unauthorized errors    to: <http://webpageA>    - error:    - forbidden    # Redirect path for 403 Forbidden errors    to: <http://webpageB>
In this configuration: - When an
unauthorized
(401) error occurs, the user is redirected to
<http://webpageA>
. - When a
forbidden
(403) error occurs, the user is redirected to
<http://webpageB>
. This setup allows you to handle different error conditions with specific redirects, improving the user experience by directing them to the appropriate webpage based on the error encountered. For more information on configuring error handlers in Ory Oathkeeper, including the use of the
when
key for matching specific conditions, you can refer to the Ory documentation on error handling and matchers: - [Ory Oathkeeper Error Handlers](https://www.ory.sh/docs/oathkeeper/pipeline/error) - [Ory Oathkeeper Matchers](https://www.ory.sh/docs/oathkeeper/pipeline/error#matchers)