Gracefully handle FileNotFoundError exceptions
This commit is contained in:
parent
59cc645b98
commit
798a72cb73
@ -139,6 +139,14 @@ def create_app():
|
|||||||
app.logger.fatal(error)
|
app.logger.fatal(error)
|
||||||
return jsonify({'error': str(error)}), 500
|
return jsonify({'error': str(error)}), 500
|
||||||
|
|
||||||
|
@app.errorhandler(FileNotFoundError)
|
||||||
|
def filenotfound_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
|
@auth.error_handler
|
||||||
def auth_error():
|
def auth_error():
|
||||||
app.logger.error('Access Denied')
|
app.logger.error('Access Denied')
|
||||||
|
@ -52,3 +52,19 @@ def test_wrong_method(client, mocker):
|
|||||||
headers={"Authorization": "Basic " + valid_credentials})
|
headers={"Authorization": "Basic " + valid_credentials})
|
||||||
|
|
||||||
assert response.status_code == 405
|
assert response.status_code == 405
|
||||||
|
|
||||||
|
|
||||||
|
def test_filenotfound(app, mocker):
|
||||||
|
|
||||||
|
app.config.update({
|
||||||
|
"AUTHFILE": '../tests/nonexistent-users-test.txt'
|
||||||
|
})
|
||||||
|
|
||||||
|
client = app.test_client()
|
||||||
|
|
||||||
|
valid_credentials = base64.b64encode(b"test.example.com:testpassword").decode("utf-8")
|
||||||
|
name = 'nonexistent'
|
||||||
|
response = client.get(f"/flush/{name}",
|
||||||
|
headers={"Authorization": "Basic " + valid_credentials})
|
||||||
|
|
||||||
|
assert response.status_code == 500
|
||||||
|
Loading…
x
Reference in New Issue
Block a user