Return null instead of IllegalArgumentException from hiscore

- Return null instead of throwing IllegalArgumentException from hiscore
(this was how it worked before)
- Add null checks and for hiscoreClient

Fixes #5513

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-09-17 15:25:01 +02:00
parent 45cb0bcde7
commit ec014798ca
2 changed files with 33 additions and 1 deletions

View File

@@ -45,6 +45,12 @@ public class HiscoreClient
public HiscoreResult lookup(String username, HttpUrl endpoint) throws IOException public HiscoreResult lookup(String username, HttpUrl endpoint) throws IOException
{ {
HiscoreResultBuilder resultBuilder = lookupUsername(username, endpoint); HiscoreResultBuilder resultBuilder = lookupUsername(username, endpoint);
if (resultBuilder == null)
{
return null;
}
return resultBuilder.build(); return resultBuilder.build();
} }
@@ -56,6 +62,12 @@ public class HiscoreClient
public SingleHiscoreSkillResult lookup(String username, HiscoreSkill skill, HiscoreEndpoint endpoint) throws IOException public SingleHiscoreSkillResult lookup(String username, HiscoreSkill skill, HiscoreEndpoint endpoint) throws IOException
{ {
HiscoreResultBuilder resultBuilder = lookupUsername(username, endpoint.getHiscoreURL()); HiscoreResultBuilder resultBuilder = lookupUsername(username, endpoint.getHiscoreURL());
if (resultBuilder == null)
{
return null;
}
HiscoreResult result = resultBuilder.build(); HiscoreResult result = resultBuilder.build();
Skill requested = result.getSkill(skill); Skill requested = result.getSkill(skill);
@@ -92,7 +104,7 @@ public class HiscoreClient
switch (okresponse.code()) switch (okresponse.code())
{ {
case 404: case 404:
throw new IllegalArgumentException(); return null;
default: default:
throw new IOException("Error retrieving data from Jagex Hiscores: " + okresponse.message()); throw new IOException("Error retrieving data from Jagex Hiscores: " + okresponse.message());
} }

View File

@@ -536,6 +536,13 @@ public class ChatCommandsPlugin extends Plugin implements ChatboxInputListener
try try
{ {
final SingleHiscoreSkillResult result = hiscoreClient.lookup(lookup.getName(), skill, lookup.getEndpoint()); final SingleHiscoreSkillResult result = hiscoreClient.lookup(lookup.getName(), skill, lookup.getEndpoint());
if (result == null)
{
log.warn("unable to look up skill {} for {}: not found", skill, search);
return;
}
final Skill hiscoreSkill = result.getSkill(); final Skill hiscoreSkill = result.getSkill();
final String response = new ChatMessageBuilder() final String response = new ChatMessageBuilder()
@@ -581,6 +588,12 @@ public class ChatCommandsPlugin extends Plugin implements ChatboxInputListener
{ {
HiscoreResult playerStats = hiscoreClient.lookup(player); HiscoreResult playerStats = hiscoreClient.lookup(player);
if (playerStats == null)
{
log.warn("Error fetching hiscore data: not found");
return;
}
int attack = playerStats.getAttack().getLevel(); int attack = playerStats.getAttack().getLevel();
int strength = playerStats.getStrength().getLevel(); int strength = playerStats.getStrength().getLevel();
int defence = playerStats.getDefence().getLevel(); int defence = playerStats.getDefence().getLevel();
@@ -650,6 +663,13 @@ public class ChatCommandsPlugin extends Plugin implements ChatboxInputListener
{ {
final Skill hiscoreSkill; final Skill hiscoreSkill;
final HiscoreResult result = hiscoreClient.lookup(lookup.getName(), lookup.getEndpoint()); final HiscoreResult result = hiscoreClient.lookup(lookup.getName(), lookup.getEndpoint());
if (result == null)
{
log.warn("error looking up clues: not found");
return;
}
String level = search.toLowerCase(); String level = search.toLowerCase();
switch (level) switch (level)