You've already forked snikket-web-portal
Switch to HTTP 204 to indicate no data to export
This is more robust, as it indicates the request was successfully authenticated and processed, but that there is no data to export. This is different from the URL not existing (which would also happen if the module was unavailable, which should be a notable error instead).
This commit is contained in:
committed by
Jonas Schäfer
parent
275b302531
commit
481379d03f
@@ -1129,11 +1129,13 @@ class ProsodyClient:
|
||||
self,
|
||||
*,
|
||||
session: aiohttp.ClientSession,
|
||||
) -> str:
|
||||
) -> typing.Optional[str]:
|
||||
async with session.get(
|
||||
self._xep227_endpoint("/export?stores=roster,vcard,pep"),
|
||||
) as resp:
|
||||
self._raise_error_from_response(resp)
|
||||
if resp.status == 204:
|
||||
return None
|
||||
return await resp.text()
|
||||
|
||||
@autosession
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import aiohttp
|
||||
import asyncio
|
||||
import typing
|
||||
import urllib
|
||||
@@ -188,16 +187,12 @@ async def manage_data() -> typing.Union[str, quart.Response]:
|
||||
encoded_address = urllib.parse.quote(
|
||||
user_info["address"].encode(encoding='utf-8', errors='strict')
|
||||
)
|
||||
try:
|
||||
account_data = await client.export_account_data()
|
||||
except aiohttp.ClientResponseError as e:
|
||||
if e.status == 404:
|
||||
await flash(
|
||||
_("You currently have no account data to export."),
|
||||
"alert"
|
||||
)
|
||||
else:
|
||||
raise e
|
||||
account_data = await client.export_account_data()
|
||||
if account_data is None:
|
||||
await flash(
|
||||
_("You currently have no account data to export."),
|
||||
"alert"
|
||||
)
|
||||
else:
|
||||
return Response(account_data,
|
||||
mimetype="application/xml",
|
||||
|
||||
Reference in New Issue
Block a user