Add exception handler for when pfctl operations fail
This commit is contained in:
@ -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')
|
||||
|
Reference in New Issue
Block a user