Browse Source

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.
scalafmt-draft
Alexis Hernandez 7 years ago
parent
commit
d2c75dafb1
  1. 10
      server/app/com/xsn/explorer/services/XSNService.scala
  2. 2
      server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala

10
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 }
}
}
}

2
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))

Loading…
Cancel
Save