示例#1
0
def load_plugin(name):
    try:
        __plugins__.append(__import__(name))
    except BaseException:
        log.get_logger(__name__).error("Error importing plugin `%s`", name)
        log.log_traceback(__name__)
    log.get_logger(__name__).info("Loaded plugin: %s", name)
示例#2
0
        if callback is not None:
            callback(req)

    return handler


def run_handler(req):
    if not __setup__:
        exc_setup()

    handler = __handlers__.get(req.exception.__class__, default_handler)
    return handler(req)


default_handler = generic_handler(500, 'Internal Error',
                                  callback=lambda r: log.log_traceback(__name__))


def exc_setup():
    global __setup__
    __setup__ = True
    register_handler(exceptions.ArgumentException,
                     generic_handler(400))
    register_handler(exceptions.AuthException,
                     generic_handler(401, "Not Authorized"))
    register_handler(exceptions.NotFoundException,
                     generic_handler(404, 'Not found'))
    register_handler(exceptions.RequestException,
                     generic_handler(400))
    register_handler(exceptions.InternalException,
                     generic_handler(500, 'Internal Error'))