thatscloud / pubj

A Java wrapper for the TRN PUBG REST API.
MIT License
8 stars 1 forks source link

Not working? #1

Open jfebrerc opened 6 years ago

jfebrerc commented 6 years ago

Hi, I keep getting the error "java.lang.NullPointerException". What is wrong with this code?

try( final Pubg pubg = new Pubg( apiKey ) ) { final Player player = pubg.getPlayer( "Kagnaska" ); final long kills = player.getStats() .get( new RegionSeasonModeStatsKey( EUROPE, "2018-05", DUO_FIRST_PERSON ) ) .getStats() .get( KILLS ) .getValueInt(); }catch (NullPointerException e){ STATIC.sendErrorMsg(event, "Error: " + e); }

studro commented 6 years ago

Hi @jfebrerc. Given I haven't looked at this project for around 7 months, I'm honestly very surprised that it even has been working at all (up until now at least).

I fired up some local test code with my api key. The problem appears to be that the map returned by getStats() is not populated, i.e. null, causing the NullPointerException you're seeing.

As to why that's the case, there is a property on the player object called unknownProperties, that holds any unknown properties received from the TRN REST API. It appears that the TRN REST API is currently down, returning the current message:

{code=3, error=Api is disabled due to throttling we are getting from Bluehole. Please do not contact us, we will re-enable the API as soon as it's possible. We're sorry for any trouble this has caused, but it's outside of our control.}

If you leave this issue open, I will try to find time over the coming weeks to re-jig how requests work so that a clearer exception is raised when the TRN API is down.

I don't know how long TRN's API has been down for, or when it will be coming back up. From their message, it appears from their that they're doing all they can to get it back up and running.

If you want to programatically know when it's back up using the current version of the API, the following would do the trick:

Player player = pubg.getPlayer( playerName );
boolean trnRestApiUp = !player.getUnknownProperties().containsKey( "error" );
System.out.println( "TRN API is up? " + trnRestApiUp );
if( !trnRestApiUp )
{
    System.out.println( "API error cause: " + player.getUnknownProperties().get( "error" ) );
}
jfebrerc commented 6 years ago

Ok thanks! I will leave this issue open. EDIT: what is the "getUnknownProperties()" function?