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

Add tapErrorZIO and tapErrorCauseZIO to Route and Routes

Open tjarvstrand opened this issue 1 year ago • 6 comments

Useful for things like error logging or reporting to external services such as Sentry.

tjarvstrand avatar Mar 30 '24 16:03 tjarvstrand

Codecov Report

Attention: Patch coverage is 0% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 64.34%. Comparing base (709b459) to head (006b320).

Files Patch % Lines
...io-http/shared/src/main/scala/zio/http/Route.scala 0.00% 8 Missing :warning:
...o-http/shared/src/main/scala/zio/http/Routes.scala 0.00% 2 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2755      +/-   ##
==========================================
- Coverage   64.42%   64.34%   -0.08%     
==========================================
  Files         148      148              
  Lines        8668     8678      +10     
  Branches     1589     1545      -44     
==========================================
  Hits         5584     5584              
- Misses       3084     3094      +10     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Mar 30 '24 16:03 codecov-commenter

Thanks for the feedback!

tjarvstrand avatar Jul 04 '24 11:07 tjarvstrand

@tjarvstrand Could you handle the review comments? I'd like to get this in for 3.0

987Nabil avatar Aug 27 '24 21:08 987Nabil

The tests seem to fail on something unrelated to my changes. Not sure if it's a fluke but I don't seem to be allowed to restart the workflow.

tjarvstrand avatar Aug 31 '24 06:08 tjarvstrand

I updated your branch. Let's see if it builds

987Nabil avatar Aug 31 '24 17:08 987Nabil

Please add some tests. For example adding a log output and use the test logger to find the message you logged. Or use a promise. Or whatever comes to your mind :)

987Nabil avatar Sep 05 '24 10:09 987Nabil

@tjarvstrand could you give this PR the finishing touch? :)

987Nabil avatar Dec 23 '24 05:12 987Nabil

Looking into writing some tests ATM. In the meantime, I think I'm lacking the context needed to make wise decisions on my own here 😄

Just to make sure I don't misunderstand, you are saying that I should basically just return the same Handled value on both what is currently line 172 and 197? E.g.:

  final def tapErrorCauseZIO[Err1 >: Err](
    f: Cause[Err] => ZIO[Any, Err1, Any],
  )(implicit trace: Trace, ev: CheckResponse[Err]): Route[Env, Err1] =
    self match {
      case Provided(route, env)                        => Provided(route.tapErrorCauseZIO(f), env)
      case Augmented(route, aspect)                    => Augmented(route.tapErrorCauseZIO(f), aspect)
      case handled @ Handled(_, _, _)                  => handled
      case Unhandled(rpm, handler, zippable, location) =>
        Unhandled(rpm, handler.tapErrorCauseZIO(f), zippable, location)
    }

EDIT: I think I figured most of it out. Everything became clearer once my mind got back into "scala mode". Please have another look.

However, I noticed that the handler of an Unhandled doesn't seem to be evaluated. Should that case also just return the same value?

tjarvstrand avatar Dec 30 '24 20:12 tjarvstrand