Hotpotato gives you a lot of flexibility when it comes to handling errors.

Below is a table of the type of handling and what methods you can use

Converting Errors
Some All
Pure mapErrorSome mapErrorAll / mapErrorAllInto
Effectful flatMapErrorSome flatMapErrorAll / flatMapErrorAllInto

Handling all errors

Required import:

import hotpotato._

Example value we will be operating on:

val result: Either[OneOf3[E1, E2, E3], String] = returnsE1()
// result: Either[OneOf3[E1, E2, E3], String] = Left(
//   Inl(hotpotato.Examples$E1)
// )

mapErrorAll: transforming all errors into different types

val x: Either[OneOf2[X2, X1], String] = result.mapErrorAll(
  (e1: E1) => X1(e1),
  (e2: E2) => X2(e2),
  (e3: E3) => X1(e3)
)
// x: Either[OneOf2[X2, X1], String] = Left(
//   Inr(Inl(X1(hotpotato.Examples$E1)))
// )

Note that duplicate types are deduplicated automatically.

mapErrorAllInto: transforming all errors into the same type

For example, you might want to convert all errors into an error message for the user.

result.mapErrorAllInto(
  e1 => s"Error is $e1",
  e2 => s"Error is $e2",
  e3 => s"Error is $e3",
)
// res0: Either[String, String] = Left("Error is hotpotato.Examples$E1")