File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
src/main/scala/de/upb/cs/swt/delphi/cli/commands Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import de.upb.cs.swt.delphi.cli.artifacts.SearchResultsJson._
2626import spray .json ._
2727
2828import scala .concurrent .duration ._
29+ import scala .util .{Success , Try }
2930
3031object 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" )
You can’t perform that action at this time.
0 commit comments