Skip to content

Commit 8fe93d4

Browse files
committed
fix: Throwing an error if user not logged in levelUp
If `levelUp` is called but the user is not logged, an exception will be thrown right away (instead of sending a request that will return an HTTP 401 anyway).
1 parent 694d2b7 commit 8fe93d4

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ export function getLeaderboardURL(questKey: string): URL {
7777
* Earns `xp` XP for the quest whose key is `questKey` for the current user.
7878
*/
7979
export async function levelUp(questKey: string, xp: number): Promise<LevelUpResponse> {
80+
if (!WA.player.isLogged) {
81+
throw new Error("You must be logged to gain XP.");
82+
}
8083
const url = new URL(`/api/quests/${questKey}/level-up`, questBaseUrl);
8184
const response = await fetch(url, {
8285
method: "POST",

0 commit comments

Comments
 (0)