mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
Return 400 if references missing from cancel broadcast
If someone tries to cancel a broadcast but the references don’t match and existing broadcast we correctly return a 404. If they don’t provide any references then we get an exception. This commit catches the missing references and returns a 400. I think this is more appropriate because it’s malformed request, rather than a well-formed request that doesn’t match our data. It also lets us write a more specific and helpful error message.
This commit is contained in:
@@ -7,7 +7,10 @@ def cap_xml_to_dict(cap_xml):
|
||||
return {
|
||||
"msgType": cap.alert.msgType.text,
|
||||
"reference": cap.alert.identifier.text,
|
||||
"references": cap.alert.references.text, # references to previous events belonging to the same alert
|
||||
"references": (
|
||||
# references to previous events belonging to the same alert
|
||||
cap.alert.references.text if cap.alert.references else None
|
||||
),
|
||||
"cap_event": cap.alert.info.event.text,
|
||||
"category": cap.alert.info.category.text,
|
||||
"expires": cap.alert.info.expires.text,
|
||||
|
||||
@@ -48,6 +48,11 @@ def create_broadcast():
|
||||
validate(broadcast_json, post_broadcast_schema)
|
||||
|
||||
if broadcast_json["msgType"] == "Cancel":
|
||||
if broadcast_json["references"] is None:
|
||||
raise BadRequestError(
|
||||
message='Missing <references>',
|
||||
status_code=400,
|
||||
)
|
||||
broadcast_message = _cancel_or_reject_broadcast(
|
||||
broadcast_json["references"].split(","),
|
||||
authenticated_service.id
|
||||
|
||||
Reference in New Issue
Block a user