This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user