Skip to content

Commit b81dfd5

Browse files
jtauschloliverguenther
authored andcommitted
Fix 500 when initializing an occurrence on a draft recurring meeting template
InitOccurrenceService#draft_template_failure returned only a message with no errors:, which crashed the API layer's ErrorBase.create_and_merge_errors(call.errors) with an ArgumentError ("expected at least one error") when it tried to build a MultipleErrors response from an empty error list. Every recurring meeting's template is in draft state right after creation, so initializing its first occurrence before moving the template out of draft always hit this 500 instead of a clean 422. Populate the recurring meeting's own errors object before returning failure, matching the errors: shape used elsewhere in this service and across the codebase.
1 parent c46bb81 commit b81dfd5

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

modules/meeting/app/services/recurring_meetings/init_occurrence_service.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def perform
6262
end
6363

6464
def draft_template_failure
65-
ServiceResult.failure(message: I18n.t("recurring_meeting.occurrence.error_template_draft"))
65+
recurring_meeting.errors.add(:base, I18n.t("recurring_meeting.occurrence.error_template_draft"))
66+
ServiceResult.failure(errors: recurring_meeting.errors)
6667
end
6768

6869
def validate_contract

modules/meeting/spec/services/recurring_meetings/init_occurrence_service_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@
6767
expect(created_meeting).to be_nil
6868
end
6969

70+
it "carries a non-empty errors object usable by the API layer" do
71+
# Regression test: draft_template_failure used to return only a
72+
# message with no errors:, which crashed
73+
# API::Errors::ErrorBase.create_and_merge_errors(call.errors) with an
74+
# ArgumentError ("expected at least one error") when the API route
75+
# tried to build a MultipleErrors response from an empty error list.
76+
expect(service_result.errors).not_to be_empty
77+
end
78+
7079
it "does not add an occurrence" do
7180
expect { instance.call(**params) }
7281
.not_to change { series.meetings.not_templated.count }

0 commit comments

Comments
 (0)