97 lines
3.4 KiB
Python
97 lines
3.4 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
错误消息配置模块
|
|
包含各种错误消息的中文映射表
|
|
"""
|
|
|
|
from typing import Dict, Any
|
|
|
|
# 验证错误消息中文映射表
|
|
VALIDATION_ERROR_MESSAGES: Dict[str, str] = {
|
|
# 字符串类型错误
|
|
"string_too_short": "字符串长度不足,至少需要{min_length}个字符",
|
|
"string_too_long": "字符串长度超出限制,最多允许{max_length}个字符",
|
|
"string_pattern_mismatch": "字符串格式不符合要求",
|
|
|
|
# 数值类型错误
|
|
"value_error.number.not_ge": "数值必须大于或等于{ge}",
|
|
"value_error.number.not_le": "数值必须小于或等于{le}",
|
|
"value_error.number.not_gt": "数值必须大于{gt}",
|
|
"value_error.number.not_lt": "数值必须小于{lt}",
|
|
|
|
# 缺失与空值错误
|
|
"missing": "缺少必填字段",
|
|
"null": "不能为空值",
|
|
"value_error.missing": "缺少必填字段",
|
|
|
|
# 类型错误
|
|
"type_error": "类型错误,期望{expected_type}",
|
|
"type_error.integer": "必须是整数类型",
|
|
"type_error.float": "必须是浮点数类型",
|
|
"type_error.string": "必须是字符串类型",
|
|
"type_error.bool": "必须是布尔类型",
|
|
"type_error.list": "必须是列表类型",
|
|
"type_error.dict": "必须是字典类型",
|
|
"type_error.date": "必须是日期类型",
|
|
"type_error.datetime": "必须是日期时间类型",
|
|
"type_error.time": "必须是时间类型",
|
|
|
|
# 值错误
|
|
"value_error": "值错误",
|
|
"value_error.any_str.max_length": "字符串长度不能超过{limit_value}",
|
|
"value_error.decimal.max_digits": "数字总位数不能超过{max_digits}",
|
|
"value_error.decimal.max_places": "小数位数不能超过{decimal_places}",
|
|
"value_error.decimal.not_finite": "数值必须是有限的",
|
|
"value_error.email": "邮箱格式不正确",
|
|
"value_error.url": "URL格式不正确",
|
|
"value_error.uuid": "UUID格式不正确",
|
|
"value_error.json": "JSON格式不正确",
|
|
|
|
# 列表相关错误
|
|
"list_type": "必须是列表类型",
|
|
"list_min_items": "列表至少需要{min_items}个元素",
|
|
"list_max_items": "列表最多允许{max_items}个元素",
|
|
"list_unique_items": "列表元素必须唯一",
|
|
|
|
# 日期时间相关错误
|
|
"date_from_datetime_inexact": "日期转换不准确",
|
|
"date_from_datetime_not_allowed": "不允许从日期时间转换为日期",
|
|
"time_delta_in_wrong_format": "时间增量格式错误",
|
|
|
|
# 枚举相关错误
|
|
"enum": "值必须是预设的枚举值之一",
|
|
|
|
# 布尔相关错误
|
|
"boolean_not_none": "布尔值不能为空",
|
|
|
|
# 对象相关错误
|
|
"object_extra": "不允许额外字段",
|
|
"object_invalid": "对象无效"
|
|
}
|
|
|
|
# 其他业务错误消息,可根据需要扩展
|
|
BUSINESS_ERROR_MESSAGES: Dict[str, str] = {
|
|
"record_not_found": "记录不存在",
|
|
"permission_denied": "权限不足",
|
|
"already_exists": "记录已存在",
|
|
"operation_failed": "操作失败"
|
|
}
|
|
|
|
# HTTP错误状态码对应的消息
|
|
HTTP_ERROR_MESSAGES: Dict[int, str] = {
|
|
400: "请求参数有误",
|
|
401: "未授权访问",
|
|
403: "禁止访问",
|
|
404: "资源不存在",
|
|
405: "请求方法不允许",
|
|
408: "请求超时",
|
|
409: "资源冲突",
|
|
422: "请求参数验证失败",
|
|
429: "请求过于频繁",
|
|
500: "服务器内部错误",
|
|
502: "网关错误",
|
|
503: "服务暂时不可用",
|
|
504: "网关超时"
|
|
} |