Skip to content

Commit

Permalink
Handle error messages in collection add-images
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna committed Feb 18, 2022
1 parent 1ced8a1 commit c922557
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion isic_cli/cli/collection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re
import sys

Expand All @@ -10,6 +11,8 @@
from isic_cli.cli.utils import require_login, suggest_guest_login
from isic_cli.io.http import get_collections

logger = logging.getLogger(__name__)


@click.group(short_help='Manage collections.')
@click.pass_obj
Expand Down Expand Up @@ -60,10 +63,13 @@ def add_images(ctx: IsicContext, collection_id: int, from_isic_ids):
)
for isic_id in isic_ids:
if not re.match(r'^ISIC_\d{7}$', isic_id):
click.echo(f'Found invalidly formatted ISIC ID: "{isic_id}"', err=True)
click.secho(f'Found invalidly formatted ISIC ID: "{isic_id}"', err=True, fg='red')
sys.exit(1)

r = ctx.session.post(f'collections/{collection_id}/populate-from-list/', {'isic_ids': isic_ids})
if 400 <= r.status_code <= 500:
click.secho(f'Failed to add images, error: \n{r.text}', fg='red', err=True)
sys.exit(1)
r.raise_for_status()

click.echo(
Expand Down

0 comments on commit c922557

Please sign in to comment.