Skip to content

Support passing extra fields in error response #125

@greyli

Description

@greyli

The default error response contains three fields: detail, message, and status_code. The user can add more fields or remove existing ones by register a custom error processor with @app.error_processor. However, the abort and HTTPError only accept fixed arguments for the existing three fields.

We could collect additional keyword arguments in abort and HTTPError, store them as HTTPError.addtional_fields, and return them in error response when present.

Final implementation: Added a new keyword argument extra_data to collect the additional error information. See the linked PR for more details.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions