Gracefully handle FileNotFoundError exceptions

This commit is contained in:
Ruben van Staveren 2022-03-14 15:38:38 +01:00
parent 59cc645b98
commit 798a72cb73
Signed by: ruben
GPG Key ID: 886F6BECD477A93F
2 changed files with 24 additions and 0 deletions

View File

@ -139,6 +139,14 @@ def create_app():
app.logger.fatal(error)
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
def auth_error():
app.logger.error('Access Denied')

View File

@ -52,3 +52,19 @@ def test_wrong_method(client, mocker):
headers={"Authorization": "Basic " + valid_credentials})
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