From caec62a2199c6f44f2fde14956cd6f8e487f6caa Mon Sep 17 00:00:00 2001 From: David An Date: Wed, 14 Nov 2018 10:31:00 -0500 Subject: [PATCH] better error message on too-large chunked response [risk: low] (#686) better error message on too-large chunked response --- .../dsde/firecloud/FireCloudConfig.scala | 6 ++++++ .../broadinstitute/dsde/firecloud/HttpClient.scala | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/scala/org/broadinstitute/dsde/firecloud/FireCloudConfig.scala b/src/main/scala/org/broadinstitute/dsde/firecloud/FireCloudConfig.scala index 37eb8e1fa..396760c42 100644 --- a/src/main/scala/org/broadinstitute/dsde/firecloud/FireCloudConfig.scala +++ b/src/main/scala/org/broadinstitute/dsde/firecloud/FireCloudConfig.scala @@ -196,4 +196,10 @@ object FireCloudConfig { val entityWorkspaceName: Option[String] = if (metrics.hasPath("entityWorkspaceName")) Some(metrics.getString("entityWorkspaceName")) else None val libraryNamespaces: List[String] = metrics.getStringList("libraryWorkspaceNamespace").asScala.toList } + + object Spray { + private val spray = config.getConfig("spray") + // grab a copy of this Spray setting to use when displaying an error message + lazy val chunkLimit = spray.getString("can.client.response-chunk-aggregation-limit") + } } diff --git a/src/main/scala/org/broadinstitute/dsde/firecloud/HttpClient.scala b/src/main/scala/org/broadinstitute/dsde/firecloud/HttpClient.scala index 4acf45616..3b2f12f09 100644 --- a/src/main/scala/org/broadinstitute/dsde/firecloud/HttpClient.scala +++ b/src/main/scala/org/broadinstitute/dsde/firecloud/HttpClient.scala @@ -24,6 +24,11 @@ object HttpClient { case class PerformExternalRequest(requestCompression: Boolean, request: HttpRequest) + lazy val chunkLimitDisplay = FireCloudConfig.Spray.chunkLimit + .replace("m", "MB") + .replace("k", "KB") + + def props(requestContext: RequestContext): Props = Props(new HttpClient(requestContext)) def createJsonHttpEntity(json: String) = { @@ -63,8 +68,14 @@ class HttpClient (requestContext: RequestContext) extends Actor case Success(response) => log.debug("Got response: " + response) context.parent ! RequestComplete(response) + case Failure(re:RuntimeException) if re.getMessage.startsWith("sendReceive doesn't support chunked responses") => + val message = s"The response payload was over ${HttpClient.chunkLimitDisplay} and cannot be processed. " + + s"Original request url: ${externalRequest.uri.toString}" + val customException = new FireCloudException(message, re) + log.error(message, customException) + context.parent ! RequestCompleteWithErrorReport(InternalServerError, message, customException) case Failure(error) => - val message = s"External request failed to ${externalRequest.uri.toString()}" + val message = s"External request failed to ${externalRequest.uri.toString()} - ${error.getMessage}" val customException = new FireCloudException(message, error) log.error(message, customException)