Skip to content

Commit 09f3229

Browse files
committed
refactor(handdle_source_deleted): follow the v1 API's exception-handling for consistency
1 parent c32addd commit 09f3229

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

securedrop/journalist_app/api2/events.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,19 @@ def handle_source_deleted(event: Event, minor: int) -> EventResult:
176176
# Mark as deleted all the items in the source's collection
177177
deleted_items = {item.uuid: None for item in source.collection}
178178

179-
utils.delete_collection(source.filesystem_id)
180-
return EventResult(
181-
event_id=event.id,
182-
status=(EventStatusCode.OK, None),
183-
sources={event.target.source_uuid: None},
184-
items=deleted_items,
185-
)
179+
try:
180+
utils.delete_collection(source.filesystem_id)
181+
return EventResult(
182+
event_id=event.id,
183+
status=(EventStatusCode.OK, None),
184+
sources={event.target.source_uuid: None},
185+
items=deleted_items,
186+
)
187+
except ValueError as exc:
188+
return EventResult(
189+
event_id=event.id,
190+
status=(EventStatusCode.InternalServerError, exc),
191+
)
186192

187193
@staticmethod
188194
def handle_source_conversation_deleted(event: Event, minor: int) -> EventResult:
@@ -210,6 +216,7 @@ def handle_source_conversation_deleted(event: Event, minor: int) -> EventResult:
210216
# Mark as deleted all the items in the source's collection
211217
deleted_items = {item.uuid: None for item in source.collection}
212218

219+
# NB. Does not raise exceptions from utils.delete_file_object().
213220
utils.delete_source_files(source.filesystem_id)
214221
db.session.refresh(source)
215222

securedrop/journalist_app/api2/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class EventStatusCode(IntEnum):
5656
Conflict = 409
5757
# The target UUID doesn't exist and it was a deletion request
5858
Gone = 410
59+
InternalServerError = 500
5960
NotImplemented = 501
6061

6162

0 commit comments

Comments
 (0)