Fix: app logging for Exception handling corrected for non-breaking 404 HTTPExceptions
This commit is contained in:
4
app.py
4
app.py
@@ -56,6 +56,7 @@ from flask_cors import CORS
|
|||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from flask_mail import Mail, Message
|
from flask_mail import Mail, Message
|
||||||
from flask_wtf.csrf import CSRFProtect
|
from flask_wtf.csrf import CSRFProtect
|
||||||
|
from werkzeug.exceptions import HTTPException
|
||||||
from authlib.integrations.flask_client import OAuth
|
from authlib.integrations.flask_client import OAuth
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@@ -80,6 +81,9 @@ app.logger.addHandler(handler)
|
|||||||
|
|
||||||
@app.errorhandler(Exception)
|
@app.errorhandler(Exception)
|
||||||
def internal_server_error(error):
|
def internal_server_error(error):
|
||||||
|
if isinstance(error, HTTPException) and error.code == 404:
|
||||||
|
return "Not Found", 404
|
||||||
|
|
||||||
app.logger.error('Server Error: %s', (error))
|
app.logger.error('Server Error: %s', (error))
|
||||||
app.logger.error('Request: %s %s %s %s %s',
|
app.logger.error('Request: %s %s %s %s %s',
|
||||||
request.remote_addr,
|
request.remote_addr,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ load_dotenv(find_dotenv())
|
|||||||
# CLASSES
|
# CLASSES
|
||||||
class Config:
|
class Config:
|
||||||
# Miscellaneous
|
# Miscellaneous
|
||||||
DEBUG = av.input_bool(os.getenv('DEBUG'), 'DEBUG', 'Config')
|
DEBUG = False # av.input_bool(os.getenv('DEBUG'), 'DEBUG', 'Config')
|
||||||
TESTING = False
|
TESTING = False
|
||||||
URL_HOST = os.getenv('URL_HOST')
|
URL_HOST = os.getenv('URL_HOST')
|
||||||
SECRET_KEY = os.getenv('KEY_SECRET_FLASK') # gen cmd: openssl rand -hex 32
|
SECRET_KEY = os.getenv('KEY_SECRET_FLASK') # gen cmd: openssl rand -hex 32
|
||||||
@@ -53,7 +53,7 @@ class Config:
|
|||||||
# id_currency = 1
|
# id_currency = 1
|
||||||
# id_region_delivery = 1
|
# id_region_delivery = 1
|
||||||
# Mail
|
# Mail
|
||||||
MAIL_DEBUG = av.input_bool(os.getenv('DEBUG'), 'DEBUG', 'Config')
|
MAIL_DEBUG = False # av.input_bool(os.getenv('DEBUG'), 'DEBUG', 'Config')
|
||||||
MAIL_SERVER = 'mail.partsltd.co.uk' # 'smtp.gmail.com'
|
MAIL_SERVER = 'mail.partsltd.co.uk' # 'smtp.gmail.com'
|
||||||
MAIL_PORT = 465 # 587
|
MAIL_PORT = 465 # 587
|
||||||
MAIL_USE_TLS = False
|
MAIL_USE_TLS = False
|
||||||
@@ -68,6 +68,7 @@ class Config:
|
|||||||
|
|
||||||
class DevelopmentConfig(Config):
|
class DevelopmentConfig(Config):
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
MAIL_DEBUG = True
|
||||||
# Add development-specific configuration variables
|
# Add development-specific configuration variables
|
||||||
|
|
||||||
class ProductionConfig(Config):
|
class ProductionConfig(Config):
|
||||||
@@ -76,7 +77,7 @@ class ProductionConfig(Config):
|
|||||||
|
|
||||||
# Set the configuration class based on the environment
|
# Set the configuration class based on the environment
|
||||||
# You can change 'development' to 'production' when deploying
|
# You can change 'development' to 'production' when deploying
|
||||||
config_env = 'development'
|
config_env = os.getenv('FLASK_ENV')
|
||||||
if config_env == 'development':
|
if config_env == 'development':
|
||||||
app_config = DevelopmentConfig
|
app_config = DevelopmentConfig
|
||||||
elif config_env == 'production':
|
elif config_env == 'production':
|
||||||
|
|||||||
Reference in New Issue
Block a user