Skip to content

Commit

Permalink
Add parsing error prefix back (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpdaniels authored Jan 28, 2020
1 parent a4ce9be commit ed6584c
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions core/src/main/scala/caliban/CalibanError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ object CalibanError {
msg: String,
locationInfo: Option[LocationInfo] = None,
innerThrowable: Option[Throwable] = None
) extends CalibanError {
override def toString: String = s"""Parsing error: $msg ${innerThrowable.fold("")(_.toString)}"""
}
) extends CalibanError

/**
* Describes an error that happened while validating a query.
*/
case class ValidationError(msg: String, explanatoryText: String, locationInfo: Option[LocationInfo] = None)
extends CalibanError {
override def toString: String = s"""Validation error: $msg $explanatoryText"""
}
extends CalibanError

/**
* Describes an error that happened while executing a query.
Expand All @@ -39,17 +35,7 @@ object CalibanError {
path: List[Either[String, Int]] = Nil,
locationInfo: Option[LocationInfo] = None,
innerThrowable: Option[Throwable] = None
) extends CalibanError {
override def toString: String = {
val pathString = path.map {
case Left(value) => value
case Right(value) => value.toString
}.mkString(" > ")
val field = if (pathString.isEmpty) "" else s" on field '$pathString'"
val inner = innerThrowable.fold("")(e => s" with ${e.toString}")
s"Execution error$field: $msg$inner"
}
}
) extends CalibanError

implicit def circeEncoder[F[_]](implicit ev: IsCirceEncoder[F]): F[CalibanError] =
ErrorCirce.errorValueEncoder.asInstanceOf[F[CalibanError]]
Expand All @@ -66,7 +52,7 @@ private object ErrorCirce {
case CalibanError.ParsingError(msg, locationInfo, _) =>
Json
.obj(
"message" -> msg.asJson,
"message" -> s"Parsing Error: $msg".asJson,
"locations" -> Some(locationInfo).collect {
case Some(li) => Json.arr(locationToJson(li))
}.asJson
Expand Down

0 comments on commit ed6584c

Please sign in to comment.