Jump to content

Client crashing when loading HTTP URL


Bets

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) {
            e.printStackTrace();
        }
        
        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;
    }
    @Override
    public String toString() {
        return current_rank;
    }
}

 

And this is the crash log:

-- Head --
Thread: Client thread
Stacktrace:
    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.

Guest
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • how to make animated doors?, maybe geckolib, but i don't know how to code it?
    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • so my minecraft crashes when opening my world, i played without any troubles for about 5 days and today it started tweaking.. pls help me
    • Hi guys! I am having some issues with the server crashing over and over and I was hoping to get some guidance.  Thanks in advance! Crash 1: java.lang.Error: ServerHangWatchdog detected that a single server tick took 60.00 seconds (should be max 0.05)     at net.minecraft.server.dedicated.ServerWatchdog.run(ServerWatchdog.java:43) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at java.lang.Thread.run(Thread.java:840) ~[?:?] { Crash 2: java.lang.IllegalStateException: Capability missing for eeb7f026-34b4-42f5-9164-e7736461df83     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.lambda$get$0(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at net.minecraftforge.common.util.LazyOptional.orElseThrow(LazyOptional.java:261) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:mixin,re:classloading}     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.get(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:143) ~[?:?] {}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:129) ~[?:?] {}     at com.mojang.brigadier.tree.CommandNode.canUse(CommandNode.java:65) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parseNodes(CommandDispatcher.java:359) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:349) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:317) ~[brigadier-1.1.8.jar%2376!/:?] {}     at net.minecraft.commands.Commands.m_230957_(Commands.java:237) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at net.mcreator.boh.procedures.TeleportbenProcedure.lambda$execute$2(TeleportbenProcedure.java:65) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.BohMod.lambda$tick$2(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] {re:mixin}     at net.mcreator.boh.BohMod.tick(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.__BohMod_tick_ServerTickEvent.invoke(.dynamic) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading,pl:eventbus:B}     at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.event.ForgeEventFactory.onPostServerTick(ForgeEventFactory.java:950) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:classloading}     at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:835) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:661) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at java.lang.Thread.run(Thread.java:840) ~[?:?] {}
  • Topics

×
×
  • Create New...

Important Information

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