diff --git a/acceptance_tests/app/c2cwsgiutils_app/services.py b/acceptance_tests/app/c2cwsgiutils_app/services.py index 68bb7bf4f..5ca0db0a3 100644 --- a/acceptance_tests/app/c2cwsgiutils_app/services.py +++ b/acceptance_tests/app/c2cwsgiutils_app/services.py @@ -63,9 +63,11 @@ def error(request): code = int(request.params.get('code', '500')) if code == 403: raise HTTPForbidden('bam') - elif request.params.get('db', '0') == '1': + elif request.params.get('db', '0') == 'dup': for _ in range(2): models.DBSession.add(models.Hello(value='toto')) + elif request.params.get('db', '0') == 'data': + models.DBSession.add(models.Hello(id='abcd', value='toto')) else: raise Exception('boom') return {'status': 200} diff --git a/acceptance_tests/tests/tests/test_error.py b/acceptance_tests/tests/tests/test_error.py index ea9992a03..b73da7b1a 100644 --- a/acceptance_tests/tests/tests/test_error.py +++ b/acceptance_tests/tests/tests/test_error.py @@ -11,11 +11,17 @@ def test_http_error(app_connection): def test_commit_time_db(app_connection): - error = app_connection.get_json('error', params={'db': '1'}, expected_status=400) + error = app_connection.get_json('error', params={'db': 'dup'}, expected_status=400) assert error['status'] == 400 assert 'duplicate key' in error['message'] +def test_db_data_error(app_connection): + error = app_connection.get_json('error', params={'db': 'data'}, expected_status=400) + assert error['status'] == 400 + assert 'invalid input syntax for integer' in error['message'] + + def test_other(app_connection): error = app_connection.get_json('error', expected_status=500) assert error['status'] == 500 diff --git a/c2cwsgiutils/errors.py b/c2cwsgiutils/errors.py index 99c0f2c70..c4d509bfe 100644 --- a/c2cwsgiutils/errors.py +++ b/c2cwsgiutils/errors.py @@ -94,6 +94,7 @@ def _other_error(exception: Exception, request: pyramid.request.Request) -> pyra if exception.__class__.__module__ == 'botocore.exceptions' and \ exception.__class__.__name__ == 'ClientError': return _boto_client_error(exception, request) + LOG.debug("Actual exception: %s.%s", exception.__class__.__module__, exception.__class__.__name__) return _do_error(request, 500, exception) @@ -103,6 +104,7 @@ def init(config: pyramid.config.Configurator) -> None: common_options = {'renderer': 'json', 'http_cache': 0} config.add_view(view=_http_error, context=HTTPException, **common_options) config.add_view(view=_integrity_error, context=sqlalchemy.exc.IntegrityError, **common_options) + config.add_view(view=_integrity_error, context=sqlalchemy.exc.DataError, **common_options) # We don't want to cry wolf if the user interrupted the uplad of the body config.add_view(view=_client_interrupted_error, context=ConnectionResetError, **common_options)