Skip to content

Commit 72cf090

Browse files
committed
fix: improve example
1 parent d5aa4cd commit 72cf090

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

example/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-console, antfu/no-top-level-await */
22
import KeyvFile from "keyv-file";
33
import prompts from "prompts";
4-
import { VRChat } from "vrchat";
4+
import { VRChat, VRChatError } from "vrchat";
55

66
const vrchat = new VRChat({
77
/**
@@ -32,7 +32,11 @@ const { data: user } = await vrchat
3232
.getCurrentUser({ throwOnError: true })
3333
// Since we've passed `throwOnError: true`, this will throw an error if the user is not logged in.
3434
// We can catch that error and prompt the user for their credentials.
35-
.catch(async () => {
35+
.catch(async (reason) => {
36+
// Rethrow the error if it's not a 401 Unauthorized error.
37+
if (!(reason instanceof VRChatError) || reason.statusCode !== 401)
38+
throw reason;
39+
3640
/**
3741
* Ask the user for their VRChat username and password.
3842
* You can also use environment variables, or any other method to get the credentials.

0 commit comments

Comments
 (0)