# Errorfile with conditions

**URL:** <https://discourse.haproxy.org/t/errorfile-with-conditions/6215>\
**Category:** Help!\
**Created:** [February 3, 2021, 3:16pm UTC](https://discourse.haproxy.org/t/errorfile-with-conditions/6215 "2021-02-03T15:16:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Alex1](https://discourse.haproxy.org/u/Alex1)\
**Post date:** [February 3, 2021, 3:16pm UTC](https://discourse.haproxy.org/t/errorfile-with-conditions/6215/1 "2021-02-03T15:16:57Z")

</div>

Hi,

We have backends that serve json and html pages. Is there a way to return HAProxy errors based on ACLs? For example if path begins with /json then return the internal errors in json otherwise return in html.  
What we tried:

- `http-response return status 500 errorfiles json if { status eq 500 }` masks backend errors and is not what we want.
- `errorfile` or `http-error` directives would work but because the same backend can return json or HTML we need to specify conditions but it doesn’t seem to support ACLs.
- duplicating backends and use different errorfiles is not a usable solution because we have many backends and complex ACLs to know when to return json and when to return HTML.

Looking for something similar to: `errorfiles json if { path -i -m beg /json }`

With nginx we can do that with `error_page 500 502 503 /$status.$format;`

Thanks!

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 3, 2021, 6:56pm UTC](https://discourse.haproxy.org/t/errorfile-with-conditions/6215/2 "2021-02-03T18:56:51Z")

</div>

No, it isn’t (you have already listed the workarounds above).

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 3, 2021, 8:42pm UTC](https://discourse.haproxy.org/t/errorfile-with-conditions/6215/3 "2021-02-03T20:42:00Z")

</div>

You can file feature requests on Github:

> **[Build software better, together](https://github.com/haproxy/haproxy/issues/new/choose)**
>
> xy/haproxy/issues/new/choose

---

<div class="post-metadata">

**Author:** ![Alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Alex1](https://discourse.haproxy.org/u/Alex1)\
**Post date:** [February 4, 2021, 4:23pm UTC](https://discourse.haproxy.org/t/errorfile-with-conditions/6215/4 "2021-02-04T16:23:36Z")

</div>

Thanks Lukas.
