Raise CommandError when there isn't data from the api
Currently it writes to stderr, but the code keeps running and
there is an unbound error for `project_data`
-# -*- coding: utf-8 -*-
-
"""Import project command."""
import json
import os
+import requests
from django.contrib.auth.models import User
from django.core.management import call_command
-from django.core.management.base import BaseCommand
-import requests
+from django.core.management.base import BaseCommand, CommandError
from ...models import Project
@@ -57,7 +55,7 @@ class Command(BaseCommand):
if response_data['count'] == 1:
project_data = response_data['results'][0]
else:
- self.stderr.write(
+ raise CommandError(
'Cannot find {slug} in API. Response was:\n{response}'.format(
slug=slug,
response=json.dumps(response_data),
