Skip to content

Fix 500 when setting a violation section that does not exist - #279

Merged
hkdobrev merged 1 commit into
mainfrom
fix/violation-section-not-found
Oct 25, 2026
Merged

hkdobrev merged 1 commit into
mainfrom
fix/violation-section-not-found

Conversation

@hkdobrev

Copy link
Copy Markdown
Member

PUT /violations/:id/section with 999999999 returned 500. Cause: SectionsRepository.findOneOrFail only checked for 9 digits; 999999999 has no valid election region, so SECTION_SEGMENT_BREAKDOWN didn't match and matches.groups threw a TypeError.

  • findOneOrFail now throws EntityNotFoundError for ids that don't match the section pattern → the endpoint returns 409 VIOLATION_SECTION_NOT_FOUND („Секция с този номер не съществува“ / „There is no section with this number“); GET /sections/999999999 becomes a 404 instead of a 500 too.
  • Body not exactly 9 digits → 400 VIOLATION_SECTION_INVALID_FORMAT („Номерът на секцията трябва да е точно 9 цифри“).
  • Unit tests for the repository guard and the DTO.

PUT /violations/:id/section with 999999999 returned 500: SectionsRepository
findOneOrFail only checked for 9 digits, then SECTION_SEGMENT_BREAKDOWN did
not match and reading .groups of null threw a TypeError. It now throws
EntityNotFoundError, so the endpoint answers 409 VIOLATION_SECTION_NOT_FOUND
(„Секция с този номер не съществува“) and GET /sections/:id answers 404.
A section that is not 9 digits gets a 400 VIOLATION_SECTION_INVALID_FORMAT.
@hkdobrev
hkdobrev merged commit 8aa5edd into main Oct 25, 2026
1 check passed
@hkdobrev
hkdobrev deleted the fix/violation-section-not-found branch October 25, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant