Handling exceptions of HttpResponse

I want to be able to handle cases when response is not JSON string but is some error message or whatever. In the code below, I don't know how to initialize output so that it is an empty JsLookupResult.

Any other suggestions how to properly handle HTTP responses are highly welcome.

 def getRestContent(url:String,param:String,paramValue:String): JsObject = {     val response: HttpResponse[String] = Http(url).timeout(connTimeoutMs = 10000000, readTimeoutMs = 10000000).param(param,paramValue).asString     var output = JsLookupResult     try {       output = Json.parse(response.body) \ "annotation" \ "tags"     }     catch {       case e: Exception => e.printStackTrace()     }       output.as[JsObject]   } 

Replay

Category: json Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.216 (s). 12 q(s)