Skip to content

Commit

Permalink
Improve exception log messages (#1519)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Brahm <[email protected]>
  • Loading branch information
lucasbrahm and Lucas Brahm authored Apr 27, 2024
1 parent 3fbde62 commit 37183b4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tortoise/backends/asyncpg/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ async def create_connection(self, with_db: bool) -> None:
try:
self._pool = await self.create_pool(password=self.password, **self._template)
self.log.debug("Created connection pool %s with params: %s", self._pool, self._template)
except asyncpg.InvalidCatalogNameError:
raise DBConnectionError(f"Can't establish connection to database {self.database}")
except asyncpg.InvalidCatalogNameError as ex:
msg = "Can't establish connection to "
if with_db:
msg += f"database {self.database}"
else:
msg += f"default database. Verify environment PGDATABASE. Exception: {ex}"
raise DBConnectionError(msg)

async def create_pool(self, **kwargs) -> asyncpg.Pool:
return await asyncpg.create_pool(None, **kwargs)
Expand Down

0 comments on commit 37183b4

Please sign in to comment.