title: SCALA: Error while downloading blobs from an endpoint: Unexpected character '<' at input index 0
body: <p>I'm using <strong>Databricks</strong>, writing code with <strong>Scala</strong>. I download blob files from an endpoint of an API, to which I do not have access otherwise. Sometimes I might get an html response, which should be handled in my code, but I cannot figure out, how.</p>
  
  <p>Download function:</p>
  
  <pre><code>def dl: (String =&gt; String) = { fileUrl: String =&gt; {
        val token = getToken();
            val response: HttpResponse[String] = Http(fileUrl)
            .header("Authorization", "Bearer " + token)
            .asString;
        try {
          retry(4){
  
            if (response.code != 200) {
              throw new javax.xml.ws.http.HTTPException(response.code)
            }
                    response.body;
          }
        } catch {
          case e: javax.xml.ws.http.HTTPException =&gt; {
            println("error HTTPException " + e + fileUrl);
            "failed";
          }
        }
      }}
  </code></pre>
  
  <p>In this function, if successful, I return the <strong>response.body</strong>, which in normal situations is an xml file, but sometimes I get this error, which is why I thought it might be an html response from the endpoint:</p>
  
  <pre><code>spray.json.JsonParser$ParsingException: Unexpected character '&lt;' at input index 0 (line 1, position 1), expected JSON Value: &lt;html&gt;?
  </code></pre>
  
  <p>Additionally, the response.body will be written to a JSON file, but the error actually comes from the download function.</p>
  
  <p>Could you help me, how to handle this situation?</p>
  
  <p>Thank you a lot in advance!!</p>