Skip to content

Commit

Permalink
fix: command not found
Browse files Browse the repository at this point in the history
  • Loading branch information
cnblogs-dudu committed Dec 10, 2023
1 parent cd9663a commit 53ff444
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/auth/auth-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ export namespace AuthManager {
export async function acquireToken() {
const session = await ensureSession({ createIfNone: false })

if (session === undefined) throw Error('未授权')
if (isAuthSessionExpired(session)) throw Error('授权已过期')
if (session === undefined) Alert.throwWithWarn('未授权')
if (isAuthSessionExpired(session)) {
void Alert.warn('授权已过期,请重新登录')
await logout()
}

return session.accessToken
return session?.accessToken
}

export async function updateAuthStatus() {
Expand Down
5 changes: 5 additions & 0 deletions src/infra/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ export namespace Alert {
file = trimExt ? path.basename(file, path.extname(file)) : file
void Alert.warn(`本地文件 ${file} 未关联博客园博文`)
}

export function throwWithWarn(message: string): never {
void warn(message)
throw Error(message)
}
}

0 comments on commit 53ff444

Please sign in to comment.