Commit b6e29a4d by Aeolus

接口错误提示优化

parent 04107188
......@@ -17,4 +17,4 @@ logger = logging.getLogger(__name__)
app = create_app('production')
# app = create_app(os.getenv('RUN_ENV', 'development'))
app.run('127.0.0.1', 8888)
app.run('127.0.0.1', 8888, debug=True)
......@@ -14,7 +14,7 @@ from flask import Blueprint, request
from app import db
from models.Repairs import PowerRepairModel
from utils.return_code import BASE_RESPONSE, PARAMS_INVALID
from utils.return_code import BASE_RESPONSE, PARAMS_INVALID, DUPLICATE_RECORD, SQL_ERROR
logger = logging.getLogger(__name__)
repair = Blueprint('repair', __name__)
......@@ -28,17 +28,25 @@ def update_repair():
repair_man = request.values.get("repair_man", None)
index = request.values.get("index", None)
if not nfc_id or not power_sn or not repair_content or not repair_man:
if not nfc_id or not power_sn or not repair_content or not repair_man or int(index) > 5:
return BASE_RESPONSE(**PARAMS_INVALID)
logger.info('=======================')
result = PowerRepairModel.query.filter_by(power_sn=power_sn, index=index).first()
if result:
return BASE_RESPONSE(**DUPLICATE_RECORD)
model = PowerRepairModel()
model.power_sn = power_sn
model.nfc_id = nfc_id
model.repair_content = repair_content
model.repair_mane = repair_man
model.repair_man = repair_man
model.index = index
db.session.add(model)
result = db.session.commit()
try:
db.session.add(model)
db.session.commit()
except Exception as e:
logger.info(e)
return BASE_RESPONSE(**SQL_ERROR)
return BASE_RESPONSE()
......
#!usr/bin/env python
#-*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@time: 2021/03/25
@file: __init__.py.py
@function:
@modify:
"""
\ No newline at end of file
......@@ -21,7 +21,17 @@ class BASE_RESPONSE(Response):
Response.__init__(self, result, mimetype='application/json')
SQL_ERROR = {
"error_code": 9001,
"error_message": "SQL execute error"
}
PARAMS_INVALID = {
"error_code": 1001,
"error_message": "params invalid"
}
DUPLICATE_RECORD = {
"error_code": 1002,
"error_message": "duplicate record"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment