Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion project/common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ object Config {
Dependencies.mockito,
Dependencies.scalatest,
Dependencies.scalacheck,
Dependencies.junit
Dependencies.junit,
Dependencies.jsoup
)
)

Expand Down Expand Up @@ -125,6 +126,7 @@ object Version {
val jodaConvert = "1.8.1"
val jodaTime = "2.9.3"
val base64 = "2.3.9"
val jsoup = "1.17.2"
}

object Dependencies {
Expand All @@ -138,6 +140,7 @@ object Dependencies {
lazy val mockito = "org.mockito" % "mockito-all" % Version.mockito % "test"
lazy val scalacheck = "org.scalacheck" %% "scalacheck" % Version.scalacheck % "test"
lazy val junit = "com.novocode" % "junit-interface" % Version.junit % "test"
lazy val jsoup = "org.jsoup" % "jsoup" % Version.jsoup
}


Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/solidfire/core/client/ServiceBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import static java.lang.String.format;

Expand Down Expand Up @@ -206,14 +208,14 @@ protected <TResult> TResult decodeResponse(String response, Class<TResult> resul

return result;
} catch (ClassCastException e) {
final Pattern pattern = Pattern.compile("<p> (.*?)</p>");
final Matcher matcher = pattern.matcher(response);
if (matcher.find()) {
throw new ApiServerException("Not Found", "404", matcher.group(1));
Document parsedResponse = Jsoup.parse(response);
Element pTag = parsedResponse.selectFirst("p");
if(pTag != null) {
throw new ApiServerException("Not Found", "404", pTag.text());
}
// Removes the html tags from the response.
response.replaceAll("<.*?>", "");
throw new ApiException(format("There was a problem parsing the response from the server. ( response=%s )", response), e);
String responseText = parsedResponse.text();
throw new ApiException(format("There was a problem parsing the response from the server. ( response=%s )", responseText), e);
} catch (NullPointerException | JsonParseException e) {
log.debug(response);
throw new ApiException(format("There was a problem parsing the response from the server. ( response=%s )", response), e);
Expand Down
Loading