예제 #1
0
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(code, msg, error_code)
    else:
        return APIException()
예제 #2
0
def framework_error(e):
    # 只有在flask1.0的版本中, 才能捕捉到所有的异常
    if isinstance(e, APIException):
        return e
    elif isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 10007
        return APIException(msg, code, error_code)
    else:
        return APIException()
    pass
예제 #3
0
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:
        print(app.config['DEBUG'])
        if not app.config['DEBUG']:
            return APIException()
        else:
            raise e
예제 #4
0
def frame_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:
        # 调试模式下显示错误的堆栈信息
        if not app.config('DEBUG'):
            return APIException()
        else:
            raise e
예제 #5
0
def framework_error(e):
    app.logger.info(e)
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(code, msg, error_code)
    else:
        if not app.config['DEBUG']:
            return APIException()
        else:
            raise e
예제 #6
0
def active_cdkey():
    '''激活激活码(企业级以下的用户的注册)'''
    validator = BaseValidator().get_json()
    uid = g.user.uid
    cdkey_code = validator['cdkey']
    username = validator['username']
    realname = validator['realname']
    password = validator['password']
    mobile = validator['mobile']
    email = validator['email']

    cdkey = CDKeyModel.objects.filter(
        cdkey=cdkey_code, state=True).first_or_404(msg='激活码无效,请联系相关负责人')
    employee_tuple = (ScopeEnum.CO_PROJECT, ScopeEnum.CO_OPERATE,
                      ScopeEnum.CO_USER)
    if ScopeEnum(cdkey.auth) == ScopeEnum.CO_SUPER:
        # 注册成企业超级管理员
        UserActive.active_co_super_or_admin(cdkey, uid, username, realname,
                                            password, mobile, email)
        cdkey.state = False
        cdkey.save()
    elif ScopeEnum(cdkey.auth) == ScopeEnum.CO_ADMIN:
        UserActive.active_co_super_or_admin(cdkey, uid, username, realname,
                                            password, mobile, email)
    elif ScopeEnum(cdkey.auth) in employee_tuple:
        UserActive.active_co_employee(cdkey, uid, username, realname, password,
                                      mobile, email)
    else:
        raise APIException(msg='激活码权限不足')
    return Success()
예제 #7
0
def error_404(e):
    LogService.add_error_log(str(e))
    if '/v1/' in request.url:
        return APIException('not found', 404)
    return render_template('error/error.html', **{
        'status': 404,
        'msg': '很抱歉!您访问的页面不存在'
    })
예제 #8
0
def framework(e):
    if isinstance(e, APIException):
        return e
    elif isinstance(e, HTTPException):
        return APIException(e.description, e.code, 1007)
    elif current_app.config['DEBUG']:
        raise e
    return ServerError()
예제 #9
0
def frame_workerror(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:
        return ServerError()
예제 #10
0
파일: __init__.py 프로젝트: imfht/flaskapps
 def framework_error(e):
     if isinstance(e, APIException):
         return e
     elif isinstance(e, HTTPException):
         return APIException(code=e.code, error_code=1007, msg=e.description)
     else:
         if not app.config['DEBUG']:
             return ServerError()  # 未知错误(统一为服务端异常)
         else:
             raise e
예제 #11
0
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, PageNotAnInteger):
        return APIException('分页参数错误,参数不是Integer类型', 400, 4001)
    if isinstance(e, EmptyPage):
        return APIException('分页参数错误,当前页没有数据', 400, 4001)
    if isinstance(e, HTTPException):
        code = e.code
        msg = '未定义Http异常: ' + str(e.description)
        error_code = 5008
        return APIException(msg, code, error_code)
    else:
        # TODO
        # Log处理
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #12
0
 def framework_error(e):
     if isinstance(e, APIException):
         return e
     if isinstance(e, HTTPException):
         code = e.code
         msg = e.description
         error_code = 1007
         return APIException(msg, code, error_code)
     else:
         # 系统错误,记录日志
         # logging.error(e.args)
         raise e
예제 #13
0
def framework_error(e):
    '''global error handler'''
    if isinstance(e, APIException):
        return e
    elif isinstance(e, HTTPException):
        return APIException(message=e.description,
                            code=e.code,
                            error_code=1007)
    else:
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #14
0
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:
        if app.config["DEBUG"]:
            raise e
        else:
            return ServerError()
예제 #15
0
def framework_error(e):
    if isinstance(e, APIException):  #如果是APIException,原样返回回去
        return e
    if isinstance(e, HTTPException):  #如果是HTTPException,转换成APIException
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:  #其他python异常返回一个自定义的APIException
        if not app.config['DEBUG']:  #如果当前是调试模式,则返回详细报错信息
            return ServerError()
        else:
            raise e
예제 #16
0
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:
        current_app.logger.error(e)
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #17
0
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        status_code = 1007
        return APIException(msg, code, status_code)
    else:
        # log
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #18
0
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:
        # 这里最好记录log日志,以方便查看错误原因(本项目未做log)
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #19
0
def framework_error(e):
    # flask 1.0 可以捕捉所以异常
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:
        if not app.config['DEBUG']:
            return ServerError()
        return e
    pass
예제 #20
0
def framework_error(e):
    """全局异常处理"""
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 100
        return APIException(msg, code, error_code)
    else:
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #21
0
def api_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:
        LogService.add_error_log(str(e))
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #22
0
def framework_error(e):
    if isinstance(e, APIException):
        return e
    elif isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(code=code, msg=msg, error_code=error_code)
    else:
        # 日志log记录
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #23
0
파일: ginger.py 프로젝트: fikery/giner
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:
        # 虽然不抛出异常,但是需要在log日志记录下当前异常
        # 调试模式需要抛出异常
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #24
0
def frameword_error(e):
    # e could be the following:
    # APIException
    # HTTPException
    # Exception
    if isinstance(e, APIException):
        return e
    elif isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:
        # return APIException()
        raise e
예제 #25
0
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg=msg, code=code, error_code=error_code)
    else:
        # flag = app.config['DEBUG']
        # print(flag)
        if app.config['DEBUG']:
            return e
        else:
            return ServerError()
예제 #26
0
def framework_error(e):
    #e可能是APIException,HTTPException,Exception
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:
        #调试模式把错误信息全爆出,其他情况爆出定义的have a mistake信息
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #27
0
def error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        msg = e.description
        code = e.code
        error_code = 1007
        return APIException(msg, code, error_code)
    if isinstance(e, Exception):
        # 调试模式关闭不会打开堆栈信息,开发阶段为了快速定位问题,都打开了调试模式
        # log记录,后续对错误日子分析处理的
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #28
0
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_cede = 1007
        return APIException(msg, code, error_cede)
    else:
        # log
        # 需要修改 Pycharm 运行配置
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #29
0
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        status_message = e.description
        error_code = 1007
        return APIException(status_message, code, error_code)
    else:
        # 调试模式
        # log
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e
예제 #30
0
파일: ginger.py 프로젝트: wswjuea/ginger
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1007
        return APIException(msg, code, error_code)
    else:
        # 需要添加log记录
        # 非调试模式,返回设置好的错误返回信息,反之,返回报错详细信息
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e