Skip to content

Commit

Permalink
Also catch fatal exceptions (e.g. InterruptedException) in MonadError…
Browse files Browse the repository at this point in the history
….handleError
  • Loading branch information
adamw committed Nov 12, 2024
1 parent 97ee8dc commit 783ddc8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ project/plugins/project/
.worksheet

.idea*
.vscode

.keys*

Expand All @@ -28,6 +29,6 @@ lowered.hnir
# Bloop / Metals
.bloop/
.metals/
project/metals.sbt
metals.sbt

.bsp
8 changes: 4 additions & 4 deletions core/src/main/scala/sttp/monad/MonadError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ trait MonadError[F[_]] {
def error[T](t: Throwable): F[T]
protected def handleWrappedError[T](rt: F[T])(h: PartialFunction[Throwable, F[T]]): F[T]
def handleError[T](rt: => F[T])(h: PartialFunction[Throwable, F[T]]): F[T] = {
Try(rt) match {
case Success(v) => handleWrappedError(v)(h)
case Failure(e) if h.isDefinedAt(e) => h(e)
case Failure(e) => error(e)
try handleWrappedError(rt)(h)
catch {
case e: Throwable if h.isDefinedAt(e) => h(e)
case e: Throwable => error(e)
}
}

Expand Down

0 comments on commit 783ddc8

Please sign in to comment.