Skip to content

fix(api): Return 400 for preference validation ValueErrors#23

Draft
sentry[bot] wants to merge 1 commit into
devfrom
seer/fix/api-handle-preference-valueerror
Draft

fix(api): Return 400 for preference validation ValueErrors#23
sentry[bot] wants to merge 1 commit into
devfrom
seer/fix/api-handle-preference-valueerror

Conversation

@sentry

@sentry sentry Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Previously, ValueError exceptions raised during preference validation (e.g., a positive weight for a shift count preference with |x - T|^2 expression) were caught by the generic except Exception block in core/nurse_scheduling/serve.py. This resulted in an HTTP 500 server error and an error-level log in Sentry, despite the issue being a client-side input validation failure.

This change introduces a specific except ValueError block in the /optimize-and-export-xlsx handler. It now catches these validation-related ValueErrors, logs them at a warning level, and returns an HTTP 400 Bad Request to the client. This aligns the handling of these errors with other client-side validation issues (like NotImplementedError and ValidationError), providing clearer feedback to the user and preventing unnecessary server error reports.

Fixes NURSE-SCHEDULING-16

@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.06%. Comparing base (69e9288) to head (2c4052f).

Files with missing lines Patch % Lines
core/nurse_scheduling/serve.py 33.33% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              dev      #23      +/-   ##
==========================================
- Coverage   92.12%   92.06%   -0.06%     
==========================================
  Files          46       46              
  Lines        3300     3303       +3     
  Branches      458      458              
==========================================
+ Hits         3040     3041       +1     
- Misses        161      163       +2     
  Partials       99       99              
Flag Coverage Δ
core 95.84% <33.33%> (-0.11%) ⬇️
web-frontend 88.01% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
core/nurse_scheduling/serve.py 83.54% <33.33%> (-1.99%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

0 participants