human
Complete this python program:
def api_handle_error_with_json(handler):
assistant
#Here is the Python program you requested.

    """All API requests should return JSON objects, even when unexpected errors occur.
    This decorator makes sure that all uncaught errors are not returned as HTML to the user, but instead JSON errors.
    """
    def api_handle_error_with_json_wrapper_fn(request, *args, **kwargs):
        try:
            return handler(request, *args, **kwargs)
        except PermissionDenied:
            raise
        except Http404:
            raise
        except Exception as e:
            logger.error('Error    in    JSON    view:    {}'.format(request.path))
            traceback.print_exc()
            return JsonResponseMessageError((_('Unexpected    error:    %(err)s') % {'err': e}), status=500)
    return api_handle_error_with_json_wrapper_fn