Skip to content

Commit

Permalink
fix: Failure when entirety of minehut is down
Browse files Browse the repository at this point in the history
  • Loading branch information
SantioMC committed May 17, 2024
1 parent 758c638 commit d269d7f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/kotlin/me/santio/minehututils/minehut/Minehut.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.santio.minehututils.minehut

import kong.unirest.core.Unirest
import kong.unirest.core.*
import me.santio.minehututils.cooldown.CooldownRegistry
import me.santio.minehututils.minehut.api.*
import java.time.Duration
Expand All @@ -21,7 +21,13 @@ object Minehut {
config().addDefaultHeader("Content-Type", "application/json")
config().addDefaultHeader("Accept", "application/json")
config().addDefaultHeader("User-Agent", "MinehutUtils/2.0")
config().connectTimeout(5000)
config().connectTimeout(2000)

config().interceptor(object : Interceptor {
override fun onFail(e: Exception?, request: HttpRequestSummary?, config: Config?): HttpResponse<*> {
return FailedResponse<String>(e)
}
})
}


Expand Down Expand Up @@ -77,7 +83,9 @@ object Minehut {
* @return The network stats model, or null if the request failed
*/
fun network(): SimpleStatsModel? {
val response = client.get("https://api.minehut.com/network/simple_stats").asObject(SimpleStatsModel::class.java)
val response = client.get("https://api.minehut.com/network/simple_stats")
.asObject(SimpleStatsModel::class.java)

return if (response.isSuccess) { response.body } else null
}

Expand Down

0 comments on commit d269d7f

Please sign in to comment.