File tree 1 file changed +21
-0
lines changed
src/main/scala/de/upb/cs/swt/delphi/cli/commands
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._
26
26
import spray .json ._
27
27
28
28
import scala .concurrent .duration ._
29
+ import scala .util .{Success , Try }
29
30
30
31
object SearchCommand extends Command with DefaultJsonProtocol {
31
32
@@ -65,6 +66,26 @@ object SearchCommand extends Command with DefaultJsonProtocol{
65
66
error.apply(s " The query timed out after ${took.toSeconds}%.0f seconds. " +
66
67
" To set a longer timeout, use the --timeout option." )
67
68
}
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
+
68
89
val resStr = res.body match {
69
90
case Left (v) =>
70
91
error.apply(s " Search request failed \n $v" )
You can’t perform that action at this time.
0 commit comments