Implement task API with input validation; implement error handling; refactoring
This commit is contained in:
parent
19d264a03b
commit
50aff05614
24 changed files with 612 additions and 131 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
|
|
@ -7,6 +8,7 @@ from flask import Flask
|
|||
from tofu_api.api import TofuApiBlueprint
|
||||
from tofu_api.common.config import Config
|
||||
from tofu_api.common.json import JSONProvider
|
||||
from tofu_api.common.rest import RestApiErrorHandler
|
||||
from tofu_api.dependencies import Dependencies
|
||||
|
||||
# Enable deprecation warnings in dev environment
|
||||
|
|
@ -42,6 +44,10 @@ class App(Flask):
|
|||
# Load app configuration from YAML file
|
||||
self.config.from_yaml(os.getenv('FLASK_CONFIG_FILE', default='config.yml'))
|
||||
|
||||
# Configure logging and error handling
|
||||
self.configure_logging()
|
||||
self.configure_error_handling()
|
||||
|
||||
# Initialize DI container
|
||||
self.dependencies = Dependencies()
|
||||
|
||||
|
|
@ -51,6 +57,24 @@ class App(Flask):
|
|||
# Register blueprints
|
||||
self.register_blueprint(TofuApiBlueprint(self))
|
||||
|
||||
def configure_logging(self) -> None:
|
||||
"""
|
||||
Configures the logging system.
|
||||
"""
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG if self.debug else logging.INFO,
|
||||
format='{asctime}.{msecs:03.0f} {levelname:>8} [{name}] {message}',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
style='{',
|
||||
)
|
||||
|
||||
def configure_error_handling(self) -> None:
|
||||
"""
|
||||
Registers error handlers to the app.
|
||||
"""
|
||||
error_handler = RestApiErrorHandler(debug_mode=self.debug)
|
||||
error_handler.register_error_handlers(self)
|
||||
|
||||
def init_database(self) -> None:
|
||||
"""
|
||||
Initialize database connection and models.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue