# Help with handling http error status

**URL:** <https://softwaremill.community/t/help-with-handling-http-error-status/519>\
**Category:** tapir\
**Created:** [August 25, 2025, 9:59pm UTC](https://softwaremill.community/t/help-with-handling-http-error-status/519 "2025-08-25T21:59:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Walend](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/david_walend/32/330_2.png) [@David\_Walend](https://softwaremill.community/u/David_Walend)\
**Post date:** [August 25, 2025, 9:59pm UTC](https://softwaremill.community/t/help-with-handling-http-error-status/519/1 "2025-08-25T21:59:59Z")

</div>

I’m trying to follow the example at [One-of variants — Tapir 1.x documentation](https://tapir.softwaremill.com/en/latest/endpoint/oneof.html#oneof-outputs) but I’m getting

```auto
IllegalArgumentException Cannot decode: Mismatch(500,404)

```

instead of the expected `Left[ErrorInfo,Unit]` . My endpoint looks like

`ndpont`

` .get`

` .in("_ready")`

` .in(query[List[String]]("checked"))`

` .out(statusCode(StatusCode.Ok))`

` .errorOut(`

` oneOf[ErrorInfo](`

` oneOfVariant(statusCode(StatusCode.InternalServerError).and(jsonBody[ReadyCheckFailed])), //Failed a ready check oneOfVariant(statusCode(StatusCode.NotFound).and(jsonBody[NotFound])), //404 when there's no /_ready oneOfVariant(statusCode(StatusCode.Unauthorized).and(jsonBody[Unauthorized])), //sometimes a 401 when there's no /_ready oneOfVariant(statusCode(StatusCode.InternalServerError).and(jsonBody[InternalServerError])), //Some other 500`

` )`

` )`

with  
`sealed trait ErrorInfo case class ReadyCheckFailed(failedChecks:List[String]) extends ErrorInfo`  
`case class NotFound(what: String) extends ErrorInfo `

`case class Unauthorized(realm: String) extends ErrorInfo `

`case class InternalServerError(msg: String) extends ErrorInfo`

What did I miss?

Thanks,

David

---

<div class="post-metadata">

**Author:** ![David\_Walend](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/david_walend/32/330_2.png) [@David\_Walend](https://softwaremill.community/u/David_Walend)\
**Post date:** [August 26, 2025, 4:02pm UTC](https://softwaremill.community/t/help-with-handling-http-error-status/519/2 "2025-08-26T16:02:50Z")

</div>

I figured it out. For general errors json bodies aren’t going to be there. I used `stringBody.mapTo[NotFound]` and the like instead.

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [September 2, 2025, 9:15am UTC](https://softwaremill.community/t/help-with-handling-http-error-status/519/3 "2025-09-02T09:15:00Z")

</div>

So this was when using the endpoint as a client, and receiving a 500 response with a non-JSON body? Maybe there is something we could do to make the errors better (or richer).

---

<div class="post-metadata">

**Author:** ![David\_Walend](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/david_walend/32/330_2.png) [@David\_Walend](https://softwaremill.community/u/David_Walend)\
**Post date:** [September 2, 2025, 7:41pm UTC](https://softwaremill.community/t/help-with-handling-http-error-status/519/4 "2025-09-02T19:41:02Z")

</div>

Thanks!

The scala ecosystem is maybe settling on throwing `Exception`s - because so many things can go wrong - and returning `Either[BrokenThingsYouThoughtAbout, WhatYouWant]` s . Bill Venners predicted that at NEScala in 2015 “The Good, The Bad, and The Ugly” .

It looks like `infallibleEndpoint` will give me the ugly Exceptions I want. That might be a better starting point for URLs in many cases. I sure didn’t find it on my own.

`endpoint` is going to hide the Ugly. That probably can’t change until Tapir 2.x; it breaking existing code. I don’t think you should touch it.

Maybe add a paragraph about `infallibleEndpoint` at the start of error handling in the docs?

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [September 3, 2025, 8:21am UTC](https://softwaremill.community/t/help-with-handling-http-error-status/519/5 "2025-09-03T08:21:35Z")

</div>

Ah didn’t know about Bill’s talk, it seems he was right 🙂

As for the docs, do you mean this page? [Error handling — Tapir 1.x documentation](https://tapir.softwaremill.com/en/latest/server/errors.html)

---

<div class="post-metadata">

**Author:** ![David\_Walend](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/david_walend/32/330_2.png) [@David\_Walend](https://softwaremill.community/u/David_Walend)\
**Post date:** [September 3, 2025, 2:02pm UTC](https://softwaremill.community/t/help-with-handling-http-error-status/519/6 "2025-09-03T14:02:12Z")

</div>

That’s the page. Thanks again!

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [September 19, 2025, 1:58pm UTC](https://softwaremill.community/t/help-with-handling-http-error-status/519/7 "2025-09-19T13:58:37Z")

</div>

Better late than never, but done 😉 [Add note about infallibleEndpoint · softwaremill/tapir@a172646 · GitHub](https://github.com/softwaremill/tapir/commit/a172646860654ba34e9562f6269712c84608648c)
