Github user rekhajoshm commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21684#discussion_r200737560
  
    --- Diff: 
core/src/main/scala/org/apache/spark/deploy/rest/RestSubmissionClient.scala ---
    @@ -233,30 +233,41 @@ private[spark] class RestSubmissionClient(master: 
String) extends Logging {
       private[rest] def readResponse(connection: HttpURLConnection): 
SubmitRestProtocolResponse = {
         import scala.concurrent.ExecutionContext.Implicits.global
         val responseFuture = Future {
    -      val dataStream =
    -        if (connection.getResponseCode == HttpServletResponse.SC_OK) {
    -          connection.getInputStream
    -        } else {
    -          connection.getErrorStream
    +      val responseCode = connection.getResponseCode
    +
    +      if (responseCode != HttpServletResponse.SC_OK) {
    +        val errString = 
Some(Source.fromInputStream(connection.getErrorStream())
    +          .getLines().mkString("\n"))
    +        logError(s"Server responded with error:\n${errString}")
    +        val error = new ErrorResponse
    +        if (responseCode == 
RestSubmissionServer.SC_UNKNOWN_PROTOCOL_VERSION) {
    +          error.highestProtocolVersion = 
RestSubmissionServer.PROTOCOL_VERSION
             }
    -      // If the server threw an exception while writing a response, it 
will not have a body
    -      if (dataStream == null) {
    -        throw new SubmitRestProtocolException("Server returned empty body")
    +        error.message = errString.get
    +        error
    --- End diff --
    
    Yes, glad you see. i agree this is a clean design, serving our objective of 
robustly treating non-200 response, not sending them to json parsing and 
getting unneeded exceptions there.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to