mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Remove v2 error handler for InvalidPhoneError, no longer expect to throw this exception.
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
from flask import jsonify, current_app
|
from flask import jsonify, current_app
|
||||||
from jsonschema import ValidationError
|
from jsonschema import ValidationError
|
||||||
from notifications_utils.recipients import InvalidPhoneError
|
|
||||||
from sqlalchemy.exc import DataError
|
from sqlalchemy.exc import DataError
|
||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
from app.authentication.auth import AuthError
|
from app.authentication.auth import AuthError
|
||||||
@@ -48,12 +47,6 @@ def register_errors(blueprint):
|
|||||||
def auth_error(error):
|
def auth_error(error):
|
||||||
return jsonify(error.to_dict_v2()), error.code
|
return jsonify(error.to_dict_v2()), error.code
|
||||||
|
|
||||||
@blueprint.errorhandler(InvalidPhoneError)
|
|
||||||
def invalid_phone_error(error):
|
|
||||||
current_app.logger.exception(error)
|
|
||||||
return jsonify(status_code=400,
|
|
||||||
errors=[{"error": error.__class__.__name__, "message": error.message}]), 400
|
|
||||||
|
|
||||||
@blueprint.errorhandler(Exception)
|
@blueprint.errorhandler(Exception)
|
||||||
def internal_server_error(error):
|
def internal_server_error(error):
|
||||||
current_app.logger.exception(error)
|
current_app.logger.exception(error)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import pytest
|
import pytest
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from notifications_utils.recipients import InvalidPhoneError
|
|
||||||
from sqlalchemy.exc import DataError
|
from sqlalchemy.exc import DataError
|
||||||
|
|
||||||
|
|
||||||
@@ -40,10 +39,6 @@ def app_for_test(mocker):
|
|||||||
def raising_data_error():
|
def raising_data_error():
|
||||||
raise DataError("There was a db problem", "params", "orig")
|
raise DataError("There was a db problem", "params", "orig")
|
||||||
|
|
||||||
@blue.route("raise_phone_error", methods=["GET"])
|
|
||||||
def raising_invalid_phone_error():
|
|
||||||
raise InvalidPhoneError("The phone number is wrong")
|
|
||||||
|
|
||||||
@blue.route("raise_exception", methods=["GET"])
|
@blue.route("raise_exception", methods=["GET"])
|
||||||
def raising_exception():
|
def raising_exception():
|
||||||
raise AssertionError("Raising any old exception")
|
raise AssertionError("Raising any old exception")
|
||||||
@@ -121,13 +116,3 @@ def test_internal_server_error_handler(app_for_test):
|
|||||||
error = json.loads(response.get_data(as_text=True))
|
error = json.loads(response.get_data(as_text=True))
|
||||||
assert error == {"status_code": 500,
|
assert error == {"status_code": 500,
|
||||||
"errors": [{"error": "AssertionError", "message": "Internal server error"}]}
|
"errors": [{"error": "AssertionError", "message": "Internal server error"}]}
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_phone_error_handler(app_for_test):
|
|
||||||
with app_for_test.test_request_context():
|
|
||||||
with app_for_test.test_client() as client:
|
|
||||||
response = client.get(url_for("v2_under_test.raising_invalid_phone_error"))
|
|
||||||
assert response.status_code == 400
|
|
||||||
error = json.loads(response.get_data(as_text=True))
|
|
||||||
assert error == {"status_code": 400,
|
|
||||||
"errors": [{"error": "InvalidPhoneError", "message": "The phone number is wrong"}]}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user