Skip to content

Add HTTPError.extra_data to collect additional error information#130

Merged
greyli merged 3 commits intomainfrom
additional-error-info
Sep 8, 2021
Merged

Add HTTPError.extra_data to collect additional error information#130
greyli merged 3 commits intomainfrom
additional-error-info

Conversation

@greyli
Copy link
Copy Markdown
Member

@greyli greyli commented Aug 28, 2021

Now both the abort function and HTTPError class will accept an extra_data argument, and the value (dict) will add to the error response body (top-level).

@app.get('/')
def missing():
    abort(404, message='nothing', extra_data={'code': '123', 'status': 'not_found'})

error response:

{
    "message": "nothing",
    "detail": "",
    "code": "123",
    "status": "not_found"
}

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code docstring.
  • Add an entry in CHANGES.md summarizing the change and linking to the issue and your username.
  • Add *Version changed* or *Version added* note in any relevant docs and docstring.
  • Run pytest and tox, no tests failed.

Now both the abort function and HTTPError class will accept a extra_fields argument, and the value (dict) will add to the error response body (top-level).
@greyli greyli added this to the 0.10.0 milestone Aug 28, 2021
@greyli
Copy link
Copy Markdown
Member Author

greyli commented Aug 29, 2021

Maybe extra_data will be the better name?

@greyli greyli merged commit b1160d1 into main Sep 8, 2021
@greyli greyli deleted the additional-error-info branch September 8, 2021 04:35
@greyli greyli changed the title Add HTTPError.extra_fields to collect additional error information Add HTTPError.extra_data to collect additional error information Sep 9, 2021
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.

Support passing extra fields in error response

1 participant