code: def create_api_errorhandler(**kwargs):
      r
      def api_errorhandler(e):
          if isinstance(e, RESTException):
              return e.get_response()
          elif isinstance(e, HTTPException) and e.description:
              kwargs['message'] = e.description
          if kwargs.get('status', 400) >= 500 and hasattr(g, 'sentry_event_id'):
              kwargs['error_id'] = str(g.sentry_event_id)
          return make_response(jsonify(kwargs), kwargs['status'])
      return api_errorhandler
docs: r"""Create an API error handler.
  
      E.g. register a 404 error:
  
      .. code-block:: python
  
          app.errorhandler(404)(create_api_errorhandler(
              status=404, message='Not Found'))
  
      :param \*\*kwargs: It contains the ``'status'`` and the ``'message'``
          to describe the error.