addons14/base_rest/http.py
def wrapJsonException(exception, include_description=False, extra_info=None):
    """Wrap exceptions to be rendered as JSON.

    :param exception: an instance of an exception
    :param include_description: include full description in payload
    :param extra_info: dict to provide extra keys to include in payload
    """

    get_original_headers = exception.get_headers
    exception.traceback = "".join(traceback.format_exception(*sys.exc_info()))

    def get_body(environ=None):
        res = {"code": exception.code, "name": escape(exception.name)}
        description = exception.get_description(environ)
        if config.get_misc("base_rest", "dev_mode"):
            # return exception info only if base_rest is in dev_mode
            res.update({"traceback": exception.traceback, "description": description})
        elif include_description:
            res["description"] = description
        res.update(extra_info or {})
        return JSONEncoder().encode(res)

    def get_headers(environ=None):
        """Get a list of headers."""
        _headers = [("Content-Type", "application/json")]
        for key, value in get_original_headers(environ=environ):
            if key != "Content-Type":
                _headers.append(key, value)
        return _headers

    exception.get_body = get_body
    exception.get_headers = get_headers
    if request:
        httprequest = request.httprequest
        headers = dict(httprequest.headers)
        headers.pop("Api-Key", None)
        message = (
            "RESTFULL call to url %s with method %s and params %s "
            "raise the following error %s"
        )
        args = (httprequest.url, httprequest.method, request.params, exception)
        extra = {
            "application": "REST Services",
            "url": httprequest.url,
            "method": httprequest.method,
            "params": request.params,
            "headers": headers,
            "status": exception.code,
            "exception_body": exception.get_body(),
        }
        _logger.exception(message, *args, extra=extra)
    return exception
Wrap exceptions to be rendered as JSON.

    :param exception: an instance of an exception
    :param include_description: include full description in payload
    :param extra_info: dict to provide extra keys to include in payload
    
Wrap exceptions to be rendered as JSON.
Wrap exceptions to be rendered as JSON .
def wrapJsonException(exception, include_description=False, extra_info=None):
    get_original_headers = exception.get_headers
    exception.traceback = "".join(traceback.format_exception(*sys.exc_info()))
    def get_body(environ=None):
        res = {"code": exception.code, "name": escape(exception.name)}
        description = exception.get_description(environ)
        if config.get_misc("base_rest", "dev_mode"):
            res.update({"traceback": exception.traceback, "description": description})
        elif include_description:
            res["description"] = description
        res.update(extra_info or {})
        return JSONEncoder().encode(res)
    def get_headers(environ=None):
        _headers = [("Content-Type", "application/json")]
        for key, value in get_original_headers(environ=environ):
            if key != "Content-Type":
                _headers.append(key, value)
        return _headers
    exception.get_body = get_body
    exception.get_headers = get_headers
    if request:
        httprequest = request.httprequest
        headers = dict(httprequest.headers)
        headers.pop("Api-Key", None)
        message = (
            "RESTFULL call to url %s with method %s and params %s "
            "raise the following error %s"
        )
        args = (httprequest.url, httprequest.method, request.params, exception)
        extra = {
            "application": "REST Services",
            "url": httprequest.url,
            "method": httprequest.method,
            "params": request.params,
            "headers": headers,
            "status": exception.code,
            "exception_body": exception.get_body(),
        }
        _logger.exception(message, *args, extra=extra)
    return exception
def wrapJsonException ( exception , include_description = False , extra_info = None ) : get_original_headers = exception . get_headers exception . traceback = "" . join ( traceback . format_exception ( * sys . exc_info ( ) ) ) def get_body ( environ = None ) : res = { "code" : exception . code , "name" : escape ( exception . name ) } description = exception . get_description ( environ ) if config . get_misc ( "base_rest" , "dev_mode" ) : res . update ( { "traceback" : exception . traceback , "description" : description } ) elif include_description : res [ "description" ] = description res . update ( extra_info or { } ) return JSONEncoder ( ) . encode ( res ) def get_headers ( environ = None ) : """Get a list of headers.""" _headers = [ ( "Content-Type" , "application/json" ) ] for key , value in get_original_headers ( environ = environ ) : if key != "Content-Type" : _headers . append ( key , value ) return _headers exception . get_body = get_body exception . get_headers = get_headers if request : httprequest = request . httprequest headers = dict ( httprequest . headers ) headers . pop ( "Api-Key" , None ) message = ( "RESTFULL call to url %s with method %s and params %s " "raise the following error %s" ) args = ( httprequest . url , httprequest . method , request . params , exception ) extra = { "application" : "REST Services" , "url" : httprequest . url , "method" : httprequest . method , "params" : request . params , "headers" : headers , "status" : exception . code , "exception_body" : exception . get_body ( ) , } _logger . exception ( message , * args , extra = extra ) return exception
Wrap exceptions to be rendered as JSON.
Wrap exceptions to be rendered as JSON .
"""Wrap exceptions to be rendered as JSON.

    :param exception: an instance of an exception
    :param include_description: include full description in payload
    :param extra_info: dict to provide extra keys to include in payload
    """ # return exception info only if base_rest is in dev_mode """Get a list of headers."""
exception
an instance of an exception
an instance of an exception
include_description
include full description in payload
include full description in payload
extra_info
dict to provide extra keys to include in payload
dict to provide extra keys to include in payload