Skip to content

Commit 593288e

Browse files
authored
Merge pull request #46 from delphi-hub/bugfix/errormessages
Support for detailed error messages in case of query errors
2 parents c9fe3da + 9fd9508 commit 593288e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/main/scala/de/upb/cs/swt/delphi/cli/commands/SearchCommand.scala

+21
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import de.upb.cs.swt.delphi.cli.artifacts.SearchResultsJson._
2626
import spray.json._
2727

2828
import scala.concurrent.duration._
29+
import scala.util.{Success, Try}
2930

3031
object SearchCommand extends Command with DefaultJsonProtocol{
3132

@@ -65,6 +66,26 @@ object SearchCommand extends Command with DefaultJsonProtocol{
6566
error.apply(s"The query timed out after ${took.toSeconds}%.0f seconds. " +
6667
"To set a longer timeout, use the --timeout option.")
6768
}
69+
70+
if (res.code == StatusCodes.BadRequest && !res.statusText.isEmpty) {
71+
Try(res.statusText.parseJson) match {
72+
case Success(value) =>
73+
val errorDescription = value.asJsObject
74+
val errorMessage = errorDescription.fields("msg").asInstanceOf[JsString].value
75+
76+
error.apply(f"Your query could not be processed: $errorMessage")
77+
78+
if (errorDescription.fields.contains("invalid_fields")) {
79+
val invalidFields = errorDescription.fields("invalid_fields")
80+
.asInstanceOf[JsArray].elements.map(_.asInstanceOf[JsString].value).mkString(", ")
81+
error.apply(f"The following field names are invalid: $invalidFields")
82+
}
83+
84+
case _ =>
85+
error.apply("Your query could not be processed: Unknown error")
86+
}
87+
}
88+
6889
val resStr = res.body match {
6990
case Left(v) =>
7091
error.apply(s"Search request failed \n $v")

0 commit comments

Comments
 (0)