dosubot[bot] commented on issue #30584:
URL: https://github.com/apache/superset/issues/30584#issuecomment-2407345938

   <!-- Greeting -->
   Hello, @OldrichDlouhy! I'm here to help you with your bug report. If you 
need assistance with anything else, feel free to ask.
   
   <!-- Answer -->
   I found a similar issue related to a "500 - Internal Server Error" during 
dashboard import, which was caused by a `CommandInvalidError`. The solution 
involves ensuring proper error handling and mapping the error to a 
`SupersetErrorException` or `SupersetErrorsException` with a specific status 
code and error type.
   
   To address the HTML code leakage and improve error handling:
   
   1. **Validation**: Ensure the metadata and configurations are correct. The 
`validate` method in `ImportAssetsCommand` checks these and raises 
`CommandInvalidError` if there are issues.
   
   2. **Error Handling**: Use the error handler for `CommandException` to log 
the error and return a JSON error response. If the error is a 
`CommandInvalidError`, include additional normalized messages in the response.
   
   Here's a snippet for handling the error:
   
   ```python
   @app.errorhandler(CommandException)
   def show_command_errors(ex: CommandException) -> FlaskResponse:
       logger.warning("CommandException", exc_info=True)
       if "text/html" in request.accept_mimetypes and not app.config["DEBUG"]:
           path = files("superset") / "static/assets/500.html"
           return send_file(path, max_age=0), 500
   
       extra = ex.normalized_messages() if isinstance(ex, CommandInvalidError) 
else {}
       return json_error_response(
           [
               SupersetError(
                   message=ex.message,
                   error_type=SupersetErrorType.GENERIC_COMMAND_ERROR,
                   level=get_error_level_from_status(ex.status),
                   extra=extra,
               ),
           ],
           status=ex.status,
       )
   ```
   
   Ensure this handler is set up in your Flask app to catch and process 
`CommandInvalidError` exceptions, providing a more informative error response 
<sup>[[1]](https://github.com/apache/superset/blob/master/superset/views/error_handling.py)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/superset/commands/importers/v1/assets.py)</sup>.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


-- 
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]

Reply via email to