File tree Expand file tree Collapse file tree 5 files changed +41
-16
lines changed Expand file tree Collapse file tree 5 files changed +41
-16
lines changed Original file line number Diff line number Diff line change @@ -6,13 +6,21 @@ Exceptions
6
6
==============================================================
7
7
AuthError
8
8
==============================================================
9
- .. autoclass :: polygon.websocket.__init__.AuthError
9
+ .. autoclass :: polygon.exceptions.AuthError
10
+ :members:
11
+ :undoc-members:
12
+
13
+ ==============================================================
14
+ BadResponse
15
+ ==============================================================
16
+ .. autoclass :: polygon.exceptions.BadResponse
10
17
:members:
11
18
:undoc-members:
12
19
13
20
==============================================================
14
21
NoResultsError
15
22
==============================================================
16
- .. autoclass :: polygon.rest.base .NoResultsError
23
+ .. autoclass :: polygon.exceptions .NoResultsError
17
24
:members:
18
- :undoc-members:
25
+ :undoc-members:
26
+
Original file line number Diff line number Diff line change 1
1
from .rest import RESTClient
2
- from .rest .base import NoResultsError , version
3
- from .websocket import WebSocketClient , AuthError
2
+ from .rest .base import version
3
+ from .websocket import WebSocketClient
4
+ from .exceptions import *
4
5
5
6
__version__ = version
Original file line number Diff line number Diff line change
1
+ class AuthError (Exception ):
2
+ """
3
+ Empty or invalid API key
4
+ """
5
+
6
+ pass
7
+
8
+
9
+ class BadResponse (Exception ):
10
+ """
11
+ Non-200 response from API
12
+ """
13
+
14
+ pass
15
+
16
+
17
+ class NoResultsError (Exception ):
18
+ """
19
+ Missing results key
20
+ """
21
+
22
+ pass
Original file line number Diff line number Diff line change 8
8
import pkg_resources # part of setuptools
9
9
from ..logging import get_logger
10
10
import logging
11
+ from ..exceptions import AuthError , BadResponse , NoResultsError
11
12
12
13
logger = get_logger ("RESTClient" )
13
14
version = "unknown"
17
18
pass
18
19
19
20
20
- class NoResultsError (Exception ):
21
- pass
22
-
23
-
24
21
class BaseClient :
25
22
def __init__ (
26
23
self ,
@@ -33,7 +30,7 @@ def __init__(
33
30
verbose : bool ,
34
31
):
35
32
if api_key is None :
36
- raise Exception (
33
+ raise AuthError (
37
34
f"Must specify env var POLYGON_API_KEY or pass api_key in constructor"
38
35
)
39
36
self .API_KEY = api_key
@@ -78,7 +75,7 @@ def _get(
78
75
)
79
76
80
77
if resp .status != 200 :
81
- raise Exception (resp .data .decode ("utf-8" ))
78
+ raise BadResponse (resp .data .decode ("utf-8" ))
82
79
83
80
if raw :
84
81
return resp
Original file line number Diff line number Diff line change 11
11
from websockets .exceptions import ConnectionClosedOK , ConnectionClosedError
12
12
from ..logging import get_logger
13
13
import logging
14
+ from ..exceptions import AuthError
14
15
15
16
env_key = "POLYGON_API_KEY"
16
17
logger = get_logger ("WebSocketClient" )
17
18
18
19
19
- class AuthError (Exception ):
20
- pass
21
-
22
-
23
20
class WebSocketClient :
24
21
def __init__ (
25
22
self ,
@@ -45,7 +42,7 @@ def __init__(
45
42
:return: A client.
46
43
"""
47
44
if api_key is None :
48
- raise Exception (
45
+ raise AuthError (
49
46
f"Must specify env var { env_key } or pass api_key in constructor"
50
47
)
51
48
self .api_key = api_key
You can’t perform that action at this time.
0 commit comments