fix: return JSON body for message-only 400 aborts#86
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 anerrorskey, renamed todetails). Message-only aborts fall into theelse: raise errorbranch 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