'Error handler for the API transforms a raised exception into a Flask
response, with the appropriate HTTP status code and body.
:param e: the raised Exception object
:type e: Exception'

def handle_error(self, e):

    got_request_exception.send(current_app._get_current_object(), exception=e)
    if ((not isinstance(e, HTTPException)) and current_app.propagate_exceptions):
        (exc_type, exc_value, tb) = sys.exc_info()
        if (exc_value is e):
            raise
        else:
            raise e
    headers = Headers()
    if isinstance(e, HTTPException):
        code = e.code
        default_data = {'message': getattr(e, 'description', http_status_message(code))}
        headers = e.get_response().headers
    else:
        code = 500
        default_data = {'message': http_status_message(code)}
    remove_headers = ('Content-Length',)
    for header in remove_headers:
        headers.pop(header, None)
    data = getattr(e, 'data', default_data)
    if (code and (code >= 500)):
        exc_info = sys.exc_info()
        if (exc_info[1] is None):
            exc_info = None
        current_app.log_exception(exc_info)
    help_on_404 = current_app.config.get('ERROR_404_HELP', True)
    if ((code == 404) and help_on_404):
        rules = dict([(re.sub('(<.*>)', '', rule.rule), rule.rule) for rule in current_app.url_map.iter_rules()])
        close_matches = difflib.get_close_matches(request.path, rules.keys())
        if close_matches:
            if ('message' in data):
                data['message'] = (data['message'].rstrip('.') + '.    ')
            else:
                data['message'] = ''
            data['message'] += (((('You    have    requested    this    URI    [' + request.path) + ']    but    did    you    mean    ') + '    or    '.join((rules[match] for match in close_matches))) + '    ?')
    error_cls_name = type(e).__name__
    if (error_cls_name in self.errors):
        custom_data = self.errors.get(error_cls_name, {})
        code = custom_data.get('status', 500)
        data.update(custom_data)
    if ((code == 406) and (self.default_mediatype is None)):
        supported_mediatypes = list(self.representations.keys())
        fallback_mediatype = (supported_mediatypes[0] if supported_mediatypes else 'text/plain')
        resp = self.make_response(data, code, headers, fallback_mediatype=fallback_mediatype)
    else:
        resp = self.make_response(data, code, headers)
    if (code == 401):
        resp = self.unauthorized(resp)
    return resp
