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

Default error handler example - converts every error to Error case class and sends jsonBody #4266

Merged
merged 3 commits into from
Jan 18, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixed type, some comments too
amorfis committed Jan 15, 2025
commit c862d9e8be34ed2cca4112dcc8e24bfbedc4b483
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// {cat=Error handling; effects=Future; server=Pekko HTTP; json=circe}: Error and successful outputs
// {cat=Error handling; effects=Future; server=Pekko HTTP; json=circe}: Default error handler returning errors as JSON

//> using dep com.softwaremill.sttp.tapir::tapir-core:1.11.12
//> using dep com.softwaremill.sttp.tapir::tapir-pekko-http-server:1.11.12
//> using dep com.softwaremill.sttp.tapir::tapir-json-circe:1.11.12
//> using dep org.apache.pekko::pekko-http:1.0.1
//> using dep org.apache.pekko::pekko-stream:1.0.3
//> using dep com.softwaremill.sttp.client3::core:3.10.2
//> using dep com.softwaremill.sttp.client3::circe:3.10.2"
//> using dep com.softwaremill.sttp.client3::circe:3.10.2

package sttp.tapir.examples.errors

@@ -32,14 +32,14 @@ import scala.concurrent.{Await, Future}
implicit val actorSystem: ActorSystem = ActorSystem()
import actorSystem.dispatcher

// the endpoint description
enum Severity:
case Trace, Debug, Info, Warning, Error, Fatal

case class Error(severity: Severity, message: String)

case class Person(name: String, surname: String, age: Int)

// the endpoint description
val errorJson: PublicEndpoint[Person, Unit, String, Any] =
endpoint.post
.in("person" / jsonBody[Person])