Merge pull request #5524 from deathbeam/hiscore-lookup-catch

Return null instead of IllegalArgumentException from hiscore
This commit is contained in:
Tomas Slusny
2018-09-18 10:21:38 +02:00
committed by GitHub
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
{
HiscoreResultBuilder resultBuilder = lookupUsername(username, endpoint);
if (resultBuilder == null)
{
return null;
}
return resultBuilder.build();
}
@@ -56,6 +62,12 @@ public class HiscoreClient
public SingleHiscoreSkillResult lookup(String username, HiscoreSkill skill, HiscoreEndpoint endpoint) throws IOException
{
HiscoreResultBuilder resultBuilder = lookupUsername(username, endpoint.getHiscoreURL());
if (resultBuilder == null)
{
return null;
}
HiscoreResult result = resultBuilder.build();
Skill requested = result.getSkill(skill);
@@ -92,7 +104,7 @@ public class HiscoreClient
switch (okresponse.code())
{
case 404:
throw new IllegalArgumentException();
return null;
default:
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
{
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 String response = new ChatMessageBuilder()
@@ -581,6 +588,12 @@ public class ChatCommandsPlugin extends Plugin implements ChatboxInputListener
{
HiscoreResult playerStats = hiscoreClient.lookup(player);
if (playerStats == null)
{
log.warn("Error fetching hiscore data: not found");
return;
}
int attack = playerStats.getAttack().getLevel();
int strength = playerStats.getStrength().getLevel();
int defence = playerStats.getDefence().getLevel();
@@ -650,6 +663,13 @@ public class ChatCommandsPlugin extends Plugin implements ChatboxInputListener
{
final Skill hiscoreSkill;
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();
switch (level)