mirror of
https://github.com/ZTatman/myst.git
synced 2026-11-20 20:07:59 +00:00
fix(web): catch InvalidToken in decrypt_oauth_token with actionable error message
This commit is contained in:
parent
b6486b7d5a
commit
71dd9afb59
1 changed files with 8 additions and 2 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from cryptography.fernet import Fernet
|
||||
from cryptography.fernet import Fernet, InvalidToken
|
||||
from pydantic import SecretStr
|
||||
|
||||
|
||||
|
|
@ -37,7 +37,13 @@ def encrypt_optional(fernet: Fernet | None, raw_token: str | None) -> str | None
|
|||
|
||||
|
||||
def decrypt_oauth_token(fernet: Fernet, encrypted_token: str) -> str:
|
||||
return fernet.decrypt(encrypted_token.encode()).decode()
|
||||
try:
|
||||
return fernet.decrypt(encrypted_token.encode()).decode()
|
||||
except InvalidToken:
|
||||
raise ValueError(
|
||||
"Cannot decrypt stored token — the encryption key may have changed or the "
|
||||
"token data is corrupted. The user may need to re-connect their account."
|
||||
) from None
|
||||
|
||||
|
||||
def decrypt_optional(fernet: Fernet | None, encrypted_token: str | None) -> str | None:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue