handle json parse exception
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/f92596f4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/f92596f4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/f92596f4 Branch: refs/heads/feature/test_daewon Commit: f92596f4c1a311fe2f8c45645a96ae067360bfba Parents: e8c3588 Author: Jaesang Kim <[email protected]> Authored: Wed Dec 23 12:15:08 2015 +0900 Committer: Jaesang Kim <[email protected]> Committed: Wed Dec 23 12:15:08 2015 +0900 ---------------------------------------------------------------------- .../counter/core/v2/RankingStorageGraph.scala | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f92596f4/s2counter_core/src/main/scala/s2/counter/core/v2/RankingStorageGraph.scala ---------------------------------------------------------------------- diff --git a/s2counter_core/src/main/scala/s2/counter/core/v2/RankingStorageGraph.scala b/s2counter_core/src/main/scala/s2/counter/core/v2/RankingStorageGraph.scala index 4517697..48ef1fb 100644 --- a/s2counter_core/src/main/scala/s2/counter/core/v2/RankingStorageGraph.scala +++ b/s2counter_core/src/main/scala/s2/counter/core/v2/RankingStorageGraph.scala @@ -286,14 +286,21 @@ class RankingStorageGraph(config: Config) extends RankingStorage { """.stripMargin log.debug(strJs) - val payload = Json.parse(strJs) - wsClient.url(s"$s2graphReadOnlyUrl/graphs/getEdges").post(payload).map { resp => - resp.status match { - case HttpStatus.SC_OK => - (resp.json \ "results").asOpt[List[JsValue]].getOrElse(Nil) - case _ => - throw new RuntimeException(s"failed getEdges. errCode: ${resp.status}, body: ${resp.body}, query: $payload") - } + Try { + Json.parse(strJs) + } match { + case Success(payload) => + wsClient.url(s"$s2graphReadOnlyUrl/graphs/getEdges").post(payload).map { resp => + resp.status match { + case HttpStatus.SC_OK => + (resp.json \ "results").asOpt[List[JsValue]].getOrElse(Nil) + case _ => + throw new RuntimeException(s"failed getEdges. errCode: ${resp.status}, body: ${resp.body}, query: $payload") + } + } + case Failure(ex) => + log.error(s"$ex") + Future.successful(Nil) } }
