Skip to content

Commit ccb863f

Browse files
committed
Fold api responses
1 parent e070b3c commit ccb863f

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

common/src/main/kotlin/com/lambda/module/modules/client/Discord.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ object Discord : Module(
8080
delay(1000)
8181

8282
val auth = rpc.applicationManager.authenticate()
83-
val (authResp, error) = linkDiscord(discordToken = auth.accessToken)
84-
if (error != null) return warn("Failed to link the discord account to the minecraft auth")
8583

86-
updateToken(authResp!!)
87-
discordAuth = auth
84+
linkDiscord(discordToken = auth.accessToken)
85+
.fold(
86+
success = { updateToken(it); discordAuth = auth },
87+
failure = { warn("Failed to link the discord account to the minecraft auth") },
88+
)
8889
}
8990

9091
private fun stop() {

common/src/main/kotlin/com/lambda/module/modules/client/Network.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,11 @@ object Network : Module(
7373
// If we log in right as the client responds to the encryption request, we start
7474
// a race condition where the game server haven't acknowledged the packets
7575
// and posted to the sessionserver api
76-
val (resp, error) = login(mc.session.username, hash)
77-
if (error != null) {
78-
LOG.debug("Unable to authenticate: ${error.message}")
79-
return@listenUnsafe
80-
}
81-
82-
updateToken(resp!!)
76+
login(mc.session.username, hash)
77+
.fold(
78+
success = { updateToken(it) },
79+
failure = { LOG.warn("Unable to authenticate: $it") },
80+
)
8381
}
8482
}
8583

0 commit comments

Comments
 (0)