Skip to content

Commit

Permalink
better error message on too-large chunked response [risk: low] (#686)
Browse files Browse the repository at this point in the history
better error message on too-large chunked response
  • Loading branch information
davidangb committed Nov 14, 2018
1 parent 00143d1 commit caec62a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) = {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit caec62a

Please sign in to comment.