Skip to content

fix: return JSON body for message-only 400 aborts#86

Merged
andig merged 1 commit into
mainfrom
fix/json-body-on-abort
Jul 5, 2026
Merged

fix: return JSON body for message-only 400 aborts#86
andig merged 1 commit into
mainfrom
fix/json-body-on-abort

Conversation

@andig

@andig andig commented Jul 5, 2026

Copy link
Copy Markdown
Member

Bug

api.abort(400, message) calls (e.g. "Invalid data format", "All time series must have the same length" on /optimize/charge-schedule) return a 400 with an empty, non-JSON body — clients never see the error message.

Root cause

The custom @api.errorhandler(BadRequest) only returns a JSON body for schema-validation errors (payloads carrying an errors key, renamed to details). Message-only aborts fall into the else: raise error branch and render without a JSON body.

Fix

Return error.data (i.e. {"message": ...}) for message-only aborts as well. Validation-error behavior is unchanged. Regression test included.

Found while adding the heating-parameters endpoint in #85 (which returns fit errors via api.abort(400, str(e))); raised separately since it affects existing endpoints on main independent of that PR.

🤖 Generated with Claude Code

The BadRequest errorhandler only returned a JSON body for validation
errors (payloads with an 'errors' key) and re-raised message-only
api.abort(400, msg) calls, which then rendered as a 400 with an empty
body. Clients of e.g. "Invalid data format" / "All time series must
have the same length" aborts got no error message.

Return error.data for message-only aborts as well.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
andig added a commit that referenced this pull request Jul 5, 2026
The JSON-body-on-abort fix is independent of the heating model and
affects existing endpoints on main; it now lives in its own PR. The
short-history rejection test only asserts the 400 status until #86
lands.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@andig andig merged commit 7170b49 into main Jul 5, 2026
1 check passed
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