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:
Matthew Wild
2022-01-11 11:20:57 +00:00
committed by Jonas Schäfer
parent 275b302531
commit 481379d03f
2 changed files with 9 additions and 12 deletions

View File

@@ -1129,11 +1129,13 @@ class ProsodyClient:
self, self,
*, *,
session: aiohttp.ClientSession, session: aiohttp.ClientSession,
) -> str: ) -> typing.Optional[str]:
async with session.get( async with session.get(
self._xep227_endpoint("/export?stores=roster,vcard,pep"), self._xep227_endpoint("/export?stores=roster,vcard,pep"),
) as resp: ) as resp:
self._raise_error_from_response(resp) self._raise_error_from_response(resp)
if resp.status == 204:
return None
return await resp.text() return await resp.text()
@autosession @autosession

View File

@@ -1,4 +1,3 @@
import aiohttp
import asyncio import asyncio
import typing import typing
import urllib import urllib
@@ -188,16 +187,12 @@ async def manage_data() -> typing.Union[str, quart.Response]:
encoded_address = urllib.parse.quote( encoded_address = urllib.parse.quote(
user_info["address"].encode(encoding='utf-8', errors='strict') user_info["address"].encode(encoding='utf-8', errors='strict')
) )
try:
account_data = await client.export_account_data() account_data = await client.export_account_data()
except aiohttp.ClientResponseError as e: if account_data is None:
if e.status == 404:
await flash( await flash(
_("You currently have no account data to export."), _("You currently have no account data to export."),
"alert" "alert"
) )
else:
raise e
else: else:
return Response(account_data, return Response(account_data,
mimetype="application/xml", mimetype="application/xml",