From d2c75dafb1f7c11f90b2b26c2614efecac939d42 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Sat, 17 Mar 2018 21:10:00 -0600 Subject: [PATCH] server: Fix bug related to RPC Server 1.0.3 The server was returning status 200 for most results and it is now returning 500, like when a transaction wasn't found. --- server/app/com/xsn/explorer/services/XSNService.scala | 10 +++++++++- .../xsn/explorer/services/XSNServiceRPCImplSpec.scala | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) 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))