Jump to content

Client crashing when loading HTTP URL


Recommended Posts

I have a function that loads a specific URL from an API for some data.

Sometimes I'll get an HTTP error 429 (too many requests) from the API server. When this happens for some reason the game just crashes. All I'm doing is checking an URL for some data and displaying that data on the screen.

My first idea was to somehow detect when the API returns error 429 but I don't really know how I can do that.

Link to comment
Share on other sites

15 minutes ago, diesieben07 said:

Show your code and the crash.



It's not much, but this is the code that loads the JSON:

public static String[] getRank(String username) {
        String json = null;
        try {
            json = getJson("api url" + username);
        } catch (Exception e) {
        Gson gson = new Gson();
        TheAPI theapi = gson.fromJson(json, TheAPI.class);
        return new String[] { theapi.get_current_rank() };


The result is just put in a String that's being displayed on the screen. :ph34r:

The crash log points to the return line in the code I showed before ^

Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

This is a terrible way to deal with exceptions. Or rather, it is not a way to deal with them at all. This is just putting your head in the sand.


Show the TheAPI class.


And you still have not shown the actual crash report.



This is what I've got in the TheAPI class.

public class TheAPI {
    private String current_rank;
    public String get_current_rank() {
        return current_rank;
    public void setCurrent_rank(String current_rank) {
        this.current_rank = current_rank;
    public String toString() {
        return current_rank;


And this is the crash log:

-- Head --
Thread: Client thread
    at me.main.Engine.getRank(Engine.java:361)
    at me.main.Engine.onRenderText(Engine.java:178)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_9_Engine_onRenderText_Text.invoke(.dynamic)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185)
    at net.minecraftforge.client.GuiIngameForge.renderHUDText(GuiIngameForge.java:695)
    at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:171)


Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

That is not the full exception trace. You are missing the most important part, the type and message of the exception:


And are you seriously making a HTTP request to the API every single frame, aka 60 times a second? You can't be serious.


No, it's getting called when you join a server, ones.


Is that it?

[Client thread/INFO]: [STDERR]: java.io.IOException: Server returned HTTP response code: 429 for URL: api url
[Client thread/INFO]: [STDERR]:     at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
[Client thread/INFO]: [STDERR]:     at sun.net.www.protocol.http.HttpURLConnection.access$200(Unknown Source)


Link to comment
Share on other sites

1 minute ago, diesieben07 said:

Your exception suggests otherwise.


Please stop posting snippets of code and logs.

Post the complete log and all of your classes that are mentioned in the stacktrace.



Maybe it looks like I do because I run it for like 6 times to check 6 different players.

The thing is, it works! I just want to know how to detect the "429 Error" and handle it. Is something like this even possible?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.