Skip to content

Commit 92da66d

Browse files
committed
raise an error status 400 if scan could not be fetched
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 9ea4652 commit 92da66d

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

component_catalog/api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,11 @@ class ScanDataUnavailable(APIException):
879879
default_detail = "Scan data is not available"
880880

881881

882+
class ScanFetchError(APIException):
883+
status_code = status.HTTP_400_BAD_REQUEST
884+
default_detail = "Could not fetch scan data"
885+
886+
882887
class PackageViewSet(
883888
SendAboutFilesMixin,
884889
AboutCodeFilesActionMixin,
@@ -965,6 +970,8 @@ def scan_results(self, request, uuid):
965970
project_uuid = project_info.get("uuid")
966971
scan_results_url = scancodeio.get_scan_action_url(project_uuid, "results")
967972
scan_results = scancodeio.fetch_scan_data(scan_results_url)
973+
if not scan_results:
974+
raise ScanFetchError()
968975

969976
return Response(scan_results)
970977

component_catalog/tests/test_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,13 @@ def test_api_package_viewset_scan_results_action(
15321532
action_url = reverse("api_v2:package-scan-results", args=[self.package1.uuid])
15331533
mock_is_available.return_value = True
15341534
mock_get_project_info.return_value = {"uuid": "abcdef"}
1535+
1536+
mock_fetch_scan_data.return_value = None
1537+
response = self.client.get(action_url)
1538+
self.assertEqual(400, response.status_code)
1539+
error = {'detail': ErrorDetail(string='Could not fetch scan data', code='error')}
1540+
self.assertEqual(error, response.data)
1541+
15351542
mock_fetch_scan_data.return_value = {"results": ""}
15361543
response = self.client.get(action_url)
15371544
self.assertEqual(200, response.status_code)

0 commit comments

Comments
 (0)