bito-code-review[bot] commented on PR #42643:
URL: https://github.com/apache/superset/pull/42643#issuecomment-5144561565
<!-- Bito Reply -->
The flagged issue is correct. The current implementation of
`show_superset_exception` unconditionally returns a JSON response, which
overrides Flask's default content negotiation and prevents the rendering of the
standard HTML 500 error page for browser requests. To resolve this, you should
check the request's accepted content types and fall back to the default error
handler if HTML is preferred.
Here is a concise fix for `superset/views/error_handling.py`:
```python
from flask import request
@app.errorhandler(SupersetException)
def show_superset_exception(ex: SupersetException) -> FlaskResponse:
if request.accept_mimetypes.accept_html and not
request.accept_mimetypes.accept_json:
return show_unexpected_exception(ex)
logger_func, _ = get_logger_from_status(ex.status)
logger_func(ex.message, exc_info=True)
return json_error_response(
[
SupersetError(
message=ex.message,
error_type=SupersetErrorType.GENERIC_BACKEND_ERROR,
level=get_error_level_from_status(ex.status),
),
],
status=ex.status,
)
```
There are no other comments on this PR to address.
**superset/views/error_handling.py**
```
@app.errorhandler(SupersetException)
def show_superset_exception(ex: SupersetException) -> FlaskResponse:
if request.accept_mimetypes.accept_html and not
request.accept_mimetypes.accept_json:
return show_unexpected_exception(ex)
logger_func, _ = get_logger_from_status(ex.status)
logger_func(ex.message, exc_info=True)
return json_error_response(
[
SupersetError(
message=ex.message,
error_type=SupersetErrorType.GENERIC_BACKEND_ERROR,
level=get_error_level_from_status(ex.status),
),
],
status=ex.status,
)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]