Skip to content

Commit

Permalink
尝试获取访问令牌并处理失败情况
Browse files Browse the repository at this point in the history
引入错误处理以在获取访问令牌时捕获任何潜在的异常,并适当地响应。之前,代码缺乏处理获取令牌过程中可能发生的错误的机制。此更改确保在获取令牌失败时执行备用逻辑,提高代码的健壮性。
  • Loading branch information
share121 committed Aug 7, 2024
1 parent 4b4c0ac commit 1dc58df
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ LA.init({
(async () => {
if (!(localStorage.getItem("access_token")?.startsWith("ghu_") ?? false)) {
if (new URL(location.href).searchParams.has("code")) {
await getAccessToken(new URL(location.href).searchParams.get("code")!);
try {
await getAccessToken(new URL(location.href).searchParams.get("code")!);
} catch {
getCode();
}
} else {
getCode();
}
Expand Down Expand Up @@ -229,17 +233,18 @@ LA.init({
// }).then((e) => e.json());
const { data } = await graphql({
access_token,
data: `
query {
viewer {
avatarUrl
name
repositories {
totalCount
data: JSON.stringify({
query: `
query {
viewer {
avatarUrl
name
repositories {
totalCount
}
}
}
}
`,
}`,
}),
});
return {
name: data.viewer.name,
Expand Down

0 comments on commit 1dc58df

Please sign in to comment.