Skip to content

Commit 671ea0e

Browse files
authored
Fix: missing try catch on aleph file upload (#365)
1 parent f352fff commit 671ea0e

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/aleph_client/commands/files.py

+18-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import aiohttp
1010
import typer
11+
from aiohttp import ClientResponseError
1112
from aleph.sdk import AlephHttpClient, AuthenticatedAlephHttpClient
1213
from aleph.sdk.account import _load_account
1314
from aleph.sdk.conf import settings
@@ -88,15 +89,23 @@ async def upload(
8889
logger.debug("Uploading file")
8990
result: StoreMessage
9091
status: MessageStatus
91-
result, status = await client.create_store(
92-
file_content=file_content,
93-
storage_engine=storage_engine,
94-
channel=channel,
95-
guess_mime_type=True,
96-
ref=ref,
97-
)
98-
logger.debug("Upload finished")
99-
typer.echo(f"{result.model_dump_json(indent=4)}")
92+
try:
93+
result, status = await client.create_store(
94+
file_content=file_content,
95+
storage_engine=storage_engine,
96+
channel=channel,
97+
guess_mime_type=True,
98+
ref=ref,
99+
)
100+
logger.debug("Upload finished")
101+
typer.echo(f"{result.model_dump_json(indent=4)}")
102+
except ClientResponseError as e:
103+
typer.echo(f"{e}")
104+
105+
if e.status == 413:
106+
typer.echo("File is too large to be uploaded. Please use aleph file pin")
107+
else:
108+
typer.echo(f"Error uploading file\nstatus: {e.status}\nmessage: {e.message}")
100109

101110

102111
@app.command()

0 commit comments

Comments
 (0)