added psycopg2.Error back

This commit is contained in:
Sairam Aripirala 2020-08-11 15:47:04 -04:00
parent 725fba8728
commit 2eb4dd0f9e
2 changed files with 5 additions and 0 deletions

View file

@ -350,6 +350,8 @@ class ApplicationMixin:
_attempt + 1) as connector:
yield connector
return
# Handle timeout error during cursor creation as
# operational error
elif isinstance(err, asyncio.TimeoutError):
exc = on_error(
'postgres_connector', psycopg2.OperationalError(err))
@ -684,6 +686,8 @@ class RequestHandlerMixin:
raise web.HTTPError(500, reason='Query Timeout')
elif isinstance(exc, errors.UniqueViolation):
raise web.HTTPError(409, reason='Unique Violation')
elif isinstance(exc, psycopg2.Error):
raise web.HTTPError(500, reason='Database Error')
return exc
def _on_postgres_timing(self,

View file

@ -390,6 +390,7 @@ class RequestHandlerMixinTestCase(TestCase):
execute.side_effect = psycopg2.Error()
response = self.fetch('/execute?value=1')
self.assertEqual(response.code, 500)
self.assertIn(b'Database Error', response.body)
@mock.patch('aiopg.cursor.Cursor.fetchone')
def test_postgres_programming_error(self, fetchone):