Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
崔为之
elp
Commits
a148dedb
Commit
a148dedb
authored
Nov 04, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
b4632f2c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
3 deletions
+39
-3
application/common/config.py
application/common/config.py
+5
-3
application/libs/__init__.py
application/libs/__init__.py
+1
-0
application/libs/error/__init__.py
application/libs/error/__init__.py
+13
-0
application/libs/error/exceptions.py
application/libs/error/exceptions.py
+20
-0
No files found.
application/common/config.py
View file @
a148dedb
...
...
@@ -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
}
>"
...
...
application/libs/__init__.py
View file @
a148dedb
...
...
@@ -11,5 +11,6 @@
"""
from
.config
import
ConsulConfig
,
LocalConfig
from
.error
import
ConfigKeyError
from
.flask_elasticsearch
import
FlaskElasticsearch
from
.flask_loguru
import
FlaskLoguru
application/libs/error/__init__.py
0 → 100644
View file @
a148dedb
#!/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
application/libs/error/exceptions.py
0 → 100644
View file @
a148dedb
#!/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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment