Skip to content

Commit

Permalink
Attempt to resolve issue bitcoin-s#527 where bitcoind returns html in…
Browse files Browse the repository at this point in the history
…dicating that the service is unavailable. We shouldn't throw an exception if that happens
  • Loading branch information
Christewart committed Jul 13, 2019
1 parent 31ddb89 commit 325838d
Showing 1 changed file with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,37 +227,34 @@ trait Client extends BitcoinSLogger {

val payloadF: Future[JsValue] = responseF.flatMap(getPayload)

payloadF
.map { payload =>
{

/**
* These lines are handy if you want to inspect what's being sent to and
* returned from bitcoind before it's parsed into a Scala type. However,
* there will sensitive material in some of those calls (private keys,
* XPUBs, balances, etc). It's therefore not a good idea to enable
* this logging in production.
*/
// logger.info(
// s"Command: $command ${parameters.map(_.toString).mkString(" ")}")
// logger.info(s"Payload: \n${Json.prettyPrint(payload)}")
parseResult(result = (payload \ resultKey).validate[T],
json = payload,
printError = printError,
command = command)

}
val resultF = {
payloadF.map { payload =>
/**
* These lines are handy if you want to inspect what's being sent to and
* returned from bitcoind before it's parsed into a Scala type. However,
* there will sensitive material in some of those calls (private keys,
* XPUBs, balances, etc). It's therefore not a good idea to enable
* this logging in production.
*/
// logger.info(
// s"Command: $command ${parameters.map(_.toString).mkString(" ")}")
// logger.info(s"Payload: \n${Json.prettyPrint(payload)}")
parseResult(result = (payload \ resultKey).validate[T],
json = payload,
printError = printError,
command = command)
}
.recover {
// this can contain sensitive information, so only log this
// if not on mainnet
case err: JsonParseException if network != MainNet =>
logger.error(s"Error when parsing result of command: $command")
logger.error(s"Parameters: ${Json.stringify(JsArray(parameters))}")
logger.error(s"Sent HTTP request: $request")
logger.error(s"Error: $err")
throw err
}
resultF.failed.foreach(err => {
if (network != MainNet) {
logger.error(s"Error when parsing result of command: $command")
logger.error(s"Parameters: ${Json.stringify(JsArray(parameters))}")
logger.error(s"Sent HTTP request: $request")
logger.error(s"Error: $err")
}
})

resultF
}

protected def buildRequest(
Expand Down

0 comments on commit 325838d

Please sign in to comment.