ソースを参照

[livy] Catch JSON parse/extraction errors

Erick Tryzelaar 10 年 前
コミット
01c22e608d

+ 8 - 1
apps/spark/java/livy-repl/src/main/scala/com/cloudera/hue/livy/repl/WebApp.scala

@@ -2,7 +2,8 @@ package com.cloudera.hue.livy.repl
 
 import akka.util.Timeout
 import com.cloudera.hue.livy.ExecuteRequest
-import org.json4s.{DefaultFormats, Formats}
+import com.fasterxml.jackson.core.JsonParseException
+import org.json4s.{MappingException, DefaultFormats, Formats}
 import org.scalatra.json._
 import org.scalatra.{Accepted, AsyncResult, FutureSupport, ScalatraServlet}
 
@@ -54,4 +55,10 @@ class WebApp(interpreter: SparkInterpreter) extends ScalatraServlet with FutureS
     }
     Accepted()
   }
+
+  error {
+    case e: JsonParseException => halt(400, e.getMessage)
+    case e: MappingException => halt(400, e.getMessage)
+    case t => throw t
+  }
 }

+ 8 - 1
apps/spark/java/livy-server/src/main/scala/com/cloudera/hue/livy/server/WebApp.scala

@@ -1,6 +1,7 @@
 package com.cloudera.hue.livy.server
 
-import org.json4s.{DefaultFormats, Formats}
+import com.fasterxml.jackson.core.JsonParseException
+import org.json4s.{MappingException, DefaultFormats, Formats}
 import org.scalatra._
 import org.scalatra.json.JacksonJsonSupport
 
@@ -86,4 +87,10 @@ class WebApp(sessionManager: SessionManager)
       case None => NotFound("Session not found")
     }
   }
+
+  error {
+    case e: JsonParseException => halt(400, e.getMessage)
+    case e: MappingException => halt(400, e.getMessage)
+    case t => throw t
+  }
 }