提交 11e894a3 编写于 作者: J jiang

Clear status code information and perfect exception capture in the interface

上级 2829cc0f
......@@ -29,21 +29,21 @@ class ResponseCode():
Description: response code to web
changeLog:
"""
# Four digits are common status codes
SUCCESS = "2001"
PARAM_ERROR = "4001"
DB_NAME_ERROR = "4002"
PACK_NAME_NOT_FOUND = "4003"
CONNECT_DB_ERROR = "4004"
FILE_NOT_FOUND = "40041"
INPUT_NONE = "4005"
# Delete database module error status code
FILE_NOT_FOUND = "40041"
DELETE_DB_ERROR = "40051"
# Database initialization module error status code
CONFIGFILE_PATH_EMPTY = "50001"
FAILED_CREATE_DATABASE_TABLE = "50002"
TYPEERROR = "50003"
DATAMERGEERROR = "50004"
TYPE_ERROR = "50003"
DATA_MERGE_ERROR = "50004"
FILE_NOT_FIND_ERROR = "50005"
DIS_CONNECTION_DB = "50006"
......@@ -58,8 +58,8 @@ class ResponseCode():
DELETE_DB_ERROR: "Failed to delete database",
CONFIGFILE_PATH_EMPTY: "Initialization profile does not exist or cannot be found",
FAILED_CREATE_DATABASE_TABLE: "Failed to create database or table",
TYPEERROR: "The source code and binary path types in the initialization file are abnormal",
DATAMERGEERROR: "abnormal multi-file database integration",
TYPE_ERROR: "The source code and binary path types in the initialization file are abnormal",
DATA_MERGE_ERROR: "abnormal multi-file database integration",
FILE_NOT_FIND_ERROR: "system initialization configuration file does not exist",
DIS_CONNECTION_DB: "Unable to connect to the database, check the database configuration"}
......
......@@ -3,9 +3,9 @@ view: Request logic processing Return json format
"""
import yaml
from flask import request
from flask_restful import Resource
from flask import jsonify
from flask import current_app
from flask_restful import Resource
from sqlalchemy.exc import DisconnectionError
from packageship.application.apps.package.function.constants import ResponseCode
......@@ -144,7 +144,7 @@ class SinglePack(Resource):
current_app.logger.error(dis_connection_error)
abnormal = ResponseCode.DIS_CONNECTION_DB
except (AttributeError, Error) as attribute_error:
except (AttributeError, TypeError, Error) as attribute_error:
current_app.logger.error(attribute_error)
abnormal = ResponseCode.PACK_NAME_NOT_FOUND
if abnormal is not None:
......@@ -198,7 +198,7 @@ class SinglePack(Resource):
return jsonify(
ResponseCode.response_json(
ResponseCode.DIS_CONNECTION_DB))
except (AttributeError, Error) as attri_error:
except (AttributeError, TypeError, Error) as attri_error:
current_app.logger.error(attri_error)
return jsonify(
ResponseCode.response_json(ResponseCode.PACK_NAME_NOT_FOUND)
......@@ -367,13 +367,13 @@ class Repodatas(Resource):
ResponseCode.response_json(
ResponseCode.SUCCESS,
data=init_database_date))
except (FileNotFoundError, Error) as file_not_found:
except (FileNotFoundError, TypeError, Error) as file_not_found:
current_app.logger.error(file_not_found)
return jsonify(
ResponseCode.response_json(ResponseCode.FILE_NOT_FOUND)
)
def delete(self, *args, **kwargs):
def delete(self):
'''
description: get all database
input: database name
......@@ -401,7 +401,7 @@ class Repodatas(Resource):
return jsonify(
ResponseCode.response_json(ResponseCode.SUCCESS)
)
except Error as error:
except (FileNotFoundError, TypeError, Error) as error:
current_app.logger.error(error)
return jsonify(
ResponseCode.response_json(ResponseCode.DELETE_DB_ERROR)
......@@ -411,7 +411,7 @@ class Repodatas(Resource):
class InitSystem(Resource):
'''InitSystem'''
def post(self, *args, **kwargs):
def post(self):
"""
description: InitSystem
input:
......@@ -443,14 +443,14 @@ class InitSystem(Resource):
abnormal = ResponseCode.DIS_CONNECTION_DB
except TypeError as type_error:
LOGGER.logger.error(type_error)
abnormal = ResponseCode.TYPEERROR
abnormal = ResponseCode.TYPE_ERROR
except DataMergeException as data_merge_error:
LOGGER.logger.error(data_merge_error)
abnormal = ResponseCode.DATAMERGEERROR
abnormal = ResponseCode.DATA_MERGE_ERROR
except FileNotFoundError as file_not_found_error:
LOGGER.logger.error(file_not_found_error)
abnormal = ResponseCode.FILE_NOT_FIND_ERROR
except Error as error:
except (Error, Exception) as error:
LOGGER.logger.error(error)
abnormal = ResponseCode.FAILED_CREATE_DATABASE_TABLE
if abnormal is not None:
......
......@@ -139,6 +139,7 @@ class InitDataBase():
database:database configuration information
'''
try:
db_file = None
# 1. create a database and related tables in the database
db_name = self._create_database(database)
# 2. get the data of binary packages and source packages
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册