zio-http icon indicating copy to clipboard operation
zio-http copied to clipboard

Improve Endpoint API `BadRequest` handling

Open 987Nabil opened this issue 1 year ago • 13 comments

Currently we only return a http 400, if the endpoint API can't decode the request. That is not very helpful to the user/dev. They can't know what exactly went wrong.

Improvement

  • Make it possible to return a json or html body (setting or accept header) that let's the caller know what was missing/went wrong
  • Make it possible to configure logging of missing request data, that is rendered in a way that is helpful to the developer

987Nabil avatar Jan 24 '24 05:01 987Nabil

This would be extremely valuable 👍

swoogles avatar Jan 24 '24 05:01 swoogles

I think we need two changes:

  1. If the user does not handle the error explicitly, then we encode an error in a content-type acceptable to the HTTP client, perhaps defaulting to application/json. Moreover, we use a format that is somewhat standardized for returning error details. The main consideration, however, is just making sure that when users don't handle encoding/decoding errors, we do something that helps end-users diagnose and fix their encoding/decoding issues.
  2. We need an operator that lifts encoding/decoding errors (currently defects) into E, and we need to document that, show how it's used, and make it common practice to deal with it.

jdegoes avatar Jan 25 '24 22:01 jdegoes

@jdegoes sounds good to me. I would still have a variant of that 2. operator that just logs the codec errors in a standard way. Will be helpful in development.

987Nabil avatar Jan 26 '24 08:01 987Nabil

All right, so we have:

  1. If the user does not handle the error explicitly, then we encode an error in a content-type acceptable to the HTTP client, perhaps defaulting to application/json. Moreover, we use a format that is somewhat standardized for returning error details. The main consideration, however, is just making sure that when users don't handle encoding/decoding errors, we do something that helps end-users diagnose and fix their encoding/decoding issues.
  2. We need an operator that lifts encoding/decoding errors (currently defects) into E, and we need to document that, show how it's used, and make it common practice to deal with it.
  3. We need another operator that logs the codec errors in a standard way, useful for development.

The operators should be defined probably on Handler all the way up to Routes (including Route).

Make sense & agreed? cc @swoogles @atooni

jdegoes avatar Jan 26 '24 09:01 jdegoes

/bounty $250

jdegoes avatar Feb 08 '24 09:02 jdegoes

💎 $250 bounty created by ZIO 🙋 If you start working on this, comment /attempt #2650 along with your implementation plan 👉 To claim this bounty, submit a pull request that includes the text /claim #2650 somewhere in its body 📝 Before proceeding, please make sure you can receive payouts in your country 💵 Payment arrives in your account 2-5 days after the bounty is rewarded 💯 You keep 100% of the bounty award 🙏 Thank you for contributing to zio/zio-http!

👉 Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @987Nabil Feb 8, 2024, 4:33:35 PM #2714
🔴 @feliciien Feb 15, 2024, 4:46:39 PM WIP

algora-pbc[bot] avatar Feb 08 '24 09:02 algora-pbc[bot]

/attempt #2650

Algora profile Completed bounties Tech Active attempts Options
@987Nabil    27 ZIO bounties
+ 0 bounties from 0 projects
Scala
Cancel attempt

987Nabil avatar Feb 08 '24 16:02 987Nabil

@987Nabil: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏

algora-pbc[bot] avatar Feb 15 '24 16:02 algora-pbc[bot]

/attempt #2650

Algora profile Completed bounties Tech Active attempts Options
@feliciien 4 bounties from 1 project
MDX, Rust,
JavaScript & more
Cancel attempt

feliciien avatar Feb 15 '24 16:02 feliciien

[!NOTE] The user @987Nabil is already attempting to complete issue #2650 and claim the bounty. We recommend checking in on @987Nabil's progress, and potentially collaborating, before starting a new solution.

algora-pbc[bot] avatar Feb 15 '24 16:02 algora-pbc[bot]

The bounty is up for grabs! Everyone is welcome to /attempt #2650 🙌

algora-pbc[bot] avatar Feb 22 '24 16:02 algora-pbc[bot]

/attempt #2650 still on it.

987Nabil avatar Feb 23 '24 10:02 987Nabil

💡 @987Nabil submitted a pull request that claims the bounty. You can visit your bounty board to reward.

algora-pbc[bot] avatar Mar 03 '24 11:03 algora-pbc[bot]

🎉🎈 @987Nabil has been awarded $250! 🎈🎊

algora-pbc[bot] avatar Apr 19 '24 19:04 algora-pbc[bot]