All Downloads are FREE. Search and download functionalities are using the official Maven repository.

harness.zio.error.EncodedThrowable.scala Maven / Gradle / Ivy

There is a newer version: 5.1.3
Show newest version
package harness.zio.error

import zio.json.*

final case class EncodedThrowable(
    `class`: String,
    message: Option[String],
    cause: Option[EncodedThrowable],
) {
  def toThrowable: Throwable = new Throwable(message.getOrElse(`class`), cause.map(_.toThrowable).orNull)
}
object EncodedThrowable {

  def fromThrowable(throwable: Throwable): EncodedThrowable =
    EncodedThrowable(
      throwable.getClass.getName,
      Option(throwable.getMessage),
      Option(throwable.getCause).map(EncodedThrowable.fromThrowable),
    )

  implicit val jsonCodec: JsonCodec[EncodedThrowable] = DeriveJsonCodec.gen

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy