Commit a148dedb authored by 崔为之's avatar 崔为之 💪🏽

Update project

parent b4632f2c
......@@ -16,6 +16,8 @@ from typing import Any
from flask import Flask
from loguru import logger
from application.libs import ConfigKeyError
class ConfigHelper:
"""
......@@ -28,7 +30,7 @@ class ConfigHelper:
def __init__(self, app: Flask):
self.app = app
def __getattr__(self, name):
def __getattr__(self, name: str) -> Any:
"""
Get a config value as an attribute.
......@@ -38,8 +40,8 @@ class ConfigHelper:
try:
return self.app.config[name]
except KeyError:
logger.error(f'Key {name} error')
raise KeyError(f'Key {name} error')
logger.error(f'Key {name} not found in configuration')
raise ConfigKeyError(name)
def __repr__(self):
return f"<ConfigHelper with app {self.app}>"
......
......@@ -11,5 +11,6 @@
"""
from .config import ConsulConfig, LocalConfig
from .error import ConfigKeyError
from .flask_elasticsearch import FlaskElasticsearch
from .flask_loguru import FlaskLoguru
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
# @Version : Python 3.11.4
# @Software : Sublime Text 4
# @Author : StudentCWZ
# @Email : StudentCWZ@outlook.com
# @Date : 2023/11/4 12:13
# @File : __init__.py
# @Description : error 自定义模块
"""
from .exceptions import ConfigKeyError
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
# @Version : Python 3.11.4
# @Software : Sublime Text 4
# @Author : StudentCWZ
# @Email : StudentCWZ@outlook.com
# @Date : 2023/11/4 12:14
# @File : exceptions.py
# @Description :
"""
class ConfigKeyError(Exception):
"""
An error that is raised when a configuration key is not found.
"""
def __init__(self, key):
self.key = key
super().__init__(f'Key {self.key} not found in configuration')
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