Skip to content

fix(serve): Return 400 for invalid YAML/schema instead of 500#9

Draft
sentry[bot] wants to merge 1 commit into
devfrom
seer/fix/handle-invalid-yaml-input
Draft

fix(serve): Return 400 for invalid YAML/schema instead of 500#9
sentry[bot] wants to merge 1 commit into
devfrom
seer/fix/handle-invalid-yaml-input

Conversation

@sentry

@sentry sentry Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Previously, when users submitted malformed YAML content or data that didn't conform to the NurseSchedulingData schema to the /optimize-and-export-xlsx endpoint, the server would catch these parsing/validation errors with a broad except Exception block. This resulted in an HTTPException with a 500 status code, incorrectly indicating a server-side error, even though the issue stemmed from invalid client input.

This PR refines the error handling in core/nurse_scheduling/serve.py:

  • It now explicitly catches ruamel.yaml.YAMLError for malformed YAML input, returning an HTTPException with a 400 status code and a sanitized error message (to prevent leaking internal details).
  • It also explicitly catches pydantic.ValidationError for data that fails schema validation, returning an HTTPException with a 400 status code and a summary of the validation errors.
  • The general except Exception block is retained as a fallback for truly unexpected server-side errors, which will continue to result in a 500 status code.

This change improves the API's robustness and user experience by providing more accurate HTTP status codes and clearer error messages for client-side input issues.

Fixes JAVASCRIPT-NEXTJS-6

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