marshmallow-code / marshmallow-code/flask-smorest
Improved abort method
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 717
- Forks
- 77
- Avg merge
- 7h 49m
- Merged PRs (30d)
- 3
Description
Currently flask-smorest republishes the `abort`-method of Flask-Restful, which accepts additional keyword-args and an exception.
However, in `ErrorHandlerMixin.handle_http_exception` only `message`, `errors` and `headers` are supported as keyword-args. Everything else is ignored, which is quite confusing behaviour.
A flask-smorest specific `abort` like this would avoid confusion and allow proper type hints:
```python
def abort(http_status_code: int,
message: typing.Optional[str] = None,
errors: typing.Optional[typing.Mapping] = None,
headers: typing.Optional[typing.Mapping] = None):
"""
Raise an HTTPException for the given http_status_code.
:param http_status_code: the HTTP status code
:param message: an error message
:param errors: can be passed to define the location(s) of the error(s)
:param headers: additional headers to be passed to the response
"""
try:
flask.abort(http_status_code)
except HTTPException as err:
# re-raise exception with additional information
data = {}
if message is not None:
data["message"] = message
if errors is not None:
data["errors"] = errors
if headers is not None:
data["headers"] = headers
err.data = data
raise err
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at ErrorHandlerMixin.handle_http_exception and review how flask-smorest currently republishes Flask-Restful's abort method. Done means providing a flask-smorest-specific abort entry point that accepts the documented status, message, errors, and headers arguments, preserves them on the raised HTTP exception, and supports proper type hints.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100