Add exception handler for when pfctl operations fail

This commit is contained in:
2022-03-11 21:21:40 +01:00
parent 34f871ae75
commit 542718b956
2 changed files with 26 additions and 0 deletions

View File

@ -5,6 +5,7 @@ from ipaddress import ip_address
import re
from jail2ban.pfctl import pfctl_table_op, pfctl_cfg_read, pfctl_cfg_write
from jail2ban.auth import get_users
from subprocess import CalledProcessError
auth = HTTPBasicAuth()
@ -130,6 +131,14 @@ def create_app():
app.logger.fatal(error)
return jsonify({'error': str(error)}), 500
@app.errorhandler(CalledProcessError)
def subprocess_err(error):
'''
Show a json parsable error if the value is illegal
'''
app.logger.fatal(error)
return jsonify({'error': str(error)}), 500
@auth.error_handler
def auth_error():
app.logger.error('Access Denied')