Skip to content

Commit

Permalink
Throw nicer error message if HTML parsing failed
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Sep 12, 2024
1 parent e64c5d5 commit 6b29b4a
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,23 @@ protected MsaCode execute(final ILogger logger, final HttpClient httpClient, fin
private JsonObject extractConfig(final String html) {
switch (this.applicationDetails.getOAuthEnvironment()) {
case LIVE: {
final JsonReader jsonReader = new JsonReader(new StringReader(html.substring(html.indexOf("var ServerData = ") + 17)));
jsonReader.setLenient(true);
return JsonUtil.GSON.fromJson(jsonReader, JsonObject.class);
try {
final JsonReader jsonReader = new JsonReader(new StringReader(html.substring(html.indexOf("var ServerData = ") + 17)));
jsonReader.setLenient(true);
return JsonUtil.GSON.fromJson(jsonReader, JsonObject.class);
} catch (Throwable e) {
throw new IllegalStateException("Could not extract config from html. This most likely indicates that the login was not successful", e);
}
}
case MICROSOFT_ONLINE_COMMON:
case MICROSOFT_ONLINE_CONSUMERS: {
final JsonReader jsonReader = new JsonReader(new StringReader(html.substring(html.indexOf("$Config=") + 8)));
jsonReader.setLenient(true);
return JsonUtil.GSON.fromJson(jsonReader, JsonObject.class);
try {
final JsonReader jsonReader = new JsonReader(new StringReader(html.substring(html.indexOf("$Config=") + 8)));
jsonReader.setLenient(true);
return JsonUtil.GSON.fromJson(jsonReader, JsonObject.class);
} catch (Throwable e) {
throw new IllegalStateException("Could not extract config from html. This most likely indicates that the login was not successful", e);
}
}
default:
throw new IllegalStateException("Unsupported OAuthEnvironment: " + this.applicationDetails.getOAuthEnvironment());
Expand Down

0 comments on commit 6b29b4a

Please sign in to comment.