oauth optimizing
Build LinkLog Development Image / development-image (push) Successful in 22s

This commit is contained in:
Olaf
2026-08-26 08:20:42 +02:00
parent b35249cb86
commit 333aab8e8a
4 changed files with 31 additions and 7 deletions
+9
View File
@@ -2,6 +2,7 @@
## SPDX-License-Identifier: GPL-3.0-or-later
from urllib.parse import quote
from urllib.error import HTTPError
from fastapi import APIRouter, Depends, HTTPException
from fastapi.responses import RedirectResponse
@@ -17,6 +18,14 @@ router = APIRouter()
def oauth_start(instance: str = 'mastodon.social', user: dict = Depends(get_current_user)):
try:
authorization_url = start_authorization(user['id'], instance)
except HTTPError as error:
retry_after = error.headers.get('Retry-After') if error.headers else None
headers = {'Retry-After': retry_after} if retry_after else None
raise HTTPException(
status_code=error.code,
detail=f'Mastodon returned HTTP {error.code} while registering LinkLog. Try again later.',
headers=headers,
) from error
except Exception as error:
raise HTTPException(status_code=502, detail=f'Could not register with Mastodon: {error}') from error
return {'authorization_url': authorization_url}