diff --git a/server/app/com/xsn/explorer/services/XSNService.scala b/server/app/com/xsn/explorer/services/XSNService.scala index 138ad78..1273474 100644 --- a/server/app/com/xsn/explorer/services/XSNService.scala +++ b/server/app/com/xsn/explorer/services/XSNService.scala @@ -152,7 +152,7 @@ class XSNServiceRPCImpl @Inject() ( errorCodeMapper: Map[Int, ApplicationError])( implicit reads: Reads[A]): Option[ApplicationResult[A]] = { - Option(response) + val maybe = Option(response) .filter(_.status == 200) .flatMap { r => Try(r.json).toOption } .flatMap { json => @@ -165,5 +165,13 @@ class XSNServiceRPCImpl @Inject() ( .map(_.accumulating) } } + + // if there is no result nor error, it is probably that the server returned non 200 status + maybe.orElse { + Try(response.json) + .toOption + .flatMap { json => mapError(json, errorCodeMapper) } + .map { e => Bad(e).accumulating } + } } } diff --git a/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala b/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala index 0b975f4..bebf245 100644 --- a/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala +++ b/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala @@ -184,7 +184,7 @@ class XSNServiceRPCImplSpec extends WordSpec with MustMatchers with ScalaFutures "handle transaction not found" in { val responseBody = """{"result":null,"error":{"code":-5,"message":"No information available about transaction"},"id":null}""" val json = Json.parse(responseBody) - when(response.status).thenReturn(200) + when(response.status).thenReturn(500) when(response.json).thenReturn(json) when(request.post[String](anyString())(any())).thenReturn(Future.successful(response))