Skip to content

Commit ad53ca2

Browse files
committed
add exception class: PoolDoesNotExist
1 parent c2d9f58 commit ad53ca2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

dj_db_conn_pool/core/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# -*- coding: utf-8 -*-
22

33
import threading
4+
from django.utils.translation import ugettext_lazy as _
5+
from dj_db_conn_pool.core.exceptions import PoolDoesNotExist
46

57

68
class PoolContainer(dict):
@@ -20,7 +22,10 @@ def put(self, pool_name, pool):
2022
self[pool_name] = pool
2123

2224
def get(self, pool_name):
23-
return self[pool_name]
25+
try:
26+
return self[pool_name]
27+
except KeyError:
28+
raise PoolDoesNotExist(_('No such pool: {pool_name}').format(pool_name=pool_name))
2429

2530

2631
# 池容器,保存各个数据库的池(QueuePool)实例

dj_db_conn_pool/core/exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
class PoolDoesNotExist(Exception):
5+
pass

0 commit comments

Comments
 (0)