Skip to content

Commit e77e174

Browse files
authored
Merge pull request #131 from dapper91/dev
- fix: client and server exceptions separated.
2 parents fc1a6ae + 8638270 commit e77e174

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+531
-222
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ Changelog
22
=========
33

44

5+
2.1.0 (2025-10-31)
6+
-------------------
7+
8+
- fix: client and server exceptions separated.
9+
10+
511
2.0.1 (2025-10-28)
612
-------------------
713

README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,15 @@ which can be found in ``pjrpc.common.exceptions`` module so that error handling
359359
360360
361361
Default error list can be easily extended. All you need to create an error class inherited from
362-
``pjrpc.exc.TypedError`` and define an error code and a description message. ``pjrpc`` will be automatically
362+
``pjrpc.client.exceptions.TypedError`` and define an error code and a description message. ``pjrpc`` will be automatically
363363
deserializing custom errors for you:
364364

365365
.. code-block:: python
366366
367367
import pjrpc
368368
from pjrpc.client.backend import requests as pjrpc_client
369369
370-
class UserNotFound(pjrpc.exc.TypedError):
370+
class UserNotFound(pjrpc.client.exceptions.TypedError):
371371
CODE = 1
372372
MESSAGE = 'user not found'
373373
@@ -395,7 +395,7 @@ On the server side everything is also pretty straightforward:
395395
methods = pjrpc.server.MethodRegistry()
396396
397397
398-
class UserNotFound(pjrpc.exc.TypedError):
398+
class UserNotFound(pjrpc.server.exceptions.TypedError):
399399
CODE = 1
400400
MESSAGE = 'user not found'
401401
@@ -513,7 +513,7 @@ and Swagger UI web tool with basic auth:
513513
id: UserId
514514
515515
516-
class AlreadyExistsError(pjrpc.exc.TypedError):
516+
class AlreadyExistsError(pjrpc.server.exceptions.TypedError):
517517
"""
518518
User already registered error.
519519
"""
@@ -522,7 +522,7 @@ and Swagger UI web tool with basic auth:
522522
MESSAGE = "user already exists"
523523
524524
525-
class NotFoundError(pjrpc.exc.TypedError):
525+
class NotFoundError(pjrpc.server.exceptions.TypedError):
526526
"""
527527
User not found error.
528528
"""

docs/source/pjrpc/errors.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Errors handling
2222
-32000 to -32099 , Server error , Reserved for implementation-defined server-errors.
2323

2424

25-
Errors can be found in :py:mod:`pjrpc.common.exceptions` module. Having said that error handling
25+
Errors can be found in :py:mod:`pjrpc.client.exceptions` module. Having said that error handling
2626
is very simple and "pythonic-way":
2727

2828
.. code-block:: python
@@ -34,23 +34,23 @@ is very simple and "pythonic-way":
3434
3535
try:
3636
result = client.proxy.sum(1, 2)
37-
except pjrpc.MethodNotFound as e:
37+
except pjrpc.client.exceptions.MethodNotFound as e:
3838
print(e)
3939
4040
4141
Custom errors
4242
-------------
4343

4444
Default error list can be easily extended. All you need to create an error class inherited from
45-
:py:class:`pjrpc.common.exceptions.TypedError` and define an error code and a description message. ``pjrpc``
45+
:py:class:`pjrpc.client.exceptions.TypedError` and define an error code and a description message. ``pjrpc``
4646
will be automatically deserializing custom errors for you:
4747

4848
.. code-block:: python
4949
5050
import pjrpc
5151
from pjrpc.client.backend import requests as pjrpc_client
5252
53-
class UserNotFound(pjrpc.exc.TypedError):
53+
class UserNotFound(pjrpc.client.exceptions.TypedError):
5454
CODE = 1
5555
MESSAGE = 'user not found'
5656
@@ -81,7 +81,7 @@ On the server side everything is also pretty straightforward:
8181
methods = pjrpc.server.MethodRegistry()
8282
8383
84-
class UserNotFound(pjrpc.exc.TypedError):
84+
class UserNotFound(pjrpc.server.exceptions.TypedError):
8585
CODE = 1
8686
MESSAGE = 'user not found'
8787
@@ -123,7 +123,7 @@ to set a base error class for a particular client:
123123
from pjrpc.client.backend import requests as jrpc_client
124124
125125
126-
class ErrorV1(pjrpc.exc.TypeError, base=True):
126+
class ErrorV1(pjrpc.client.exceptions.TypeError, base=True):
127127
pass
128128
129129
@@ -132,7 +132,7 @@ to set a base error class for a particular client:
132132
MESSAGE = 'permission denied'
133133
134134
135-
class ErrorV2(pjrpc.exc.TypeError, base=True):
135+
class ErrorV2(pjrpc.client.exceptions.TypeError, base=True):
136136
pass
137137
138138

docs/source/pjrpc/quickstart.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ Error handling
278278
______________
279279

280280
``pjrpc`` implements all the errors listed in `protocol specification <https://www.jsonrpc.org/specification#error_object>`_
281-
which can be found in :py:mod:`pjrpc.common.exceptions` module so that error handling is very simple and "pythonic-way":
281+
which can be found in :py:mod:`pjrpc.client.exceptions` module so that error handling is very simple and "pythonic-way":
282282

283283
.. code-block:: python
284284
@@ -294,15 +294,15 @@ which can be found in :py:mod:`pjrpc.common.exceptions` module so that error han
294294
295295
296296
Default error list can be easily extended. All you need to create an error class inherited from
297-
:py:class:`pjrpc.common.exceptions.JsonRpcError` and define an error code and a description message. ``pjrpc``
297+
:py:class:`pjrpc.client.exceptions.TypedError` and define an error code and a description message. ``pjrpc``
298298
will be automatically deserializing custom errors for you:
299299

300300
.. code-block:: python
301301
302302
import pjrpc
303303
from pjrpc.client.backend import requests as pjrpc_client
304304
305-
class UserNotFound(pjrpc.exc.TypedError):
305+
class UserNotFound(pjrpc.client.exceptions.TypedError):
306306
CODE = 1
307307
MESSAGE = 'user not found'
308308
@@ -330,7 +330,7 @@ On the server side everything is also pretty straightforward:
330330
methods = pjrpc.server.MethodRegistry()
331331
332332
333-
class UserNotFound(pjrpc.exc.TypedError):
333+
class UserNotFound(pjrpc.server.exceptions.TypedError):
334334
CODE = 1
335335
MESSAGE = 'user not found'
336336
@@ -448,7 +448,7 @@ and Swagger UI web tool with basic auth:
448448
id: UserId
449449
450450
451-
class AlreadyExistsError(pjrpc.exc.TypedError):
451+
class AlreadyExistsError(pjrpc.server.exceptions.TypedError):
452452
"""
453453
User already registered error.
454454
"""
@@ -457,7 +457,7 @@ and Swagger UI web tool with basic auth:
457457
MESSAGE = "user already exists"
458458
459459
460-
class NotFoundError(pjrpc.exc.TypedError):
460+
class NotFoundError(pjrpc.server.exceptions.TypedError):
461461
"""
462462
User not found error.
463463
"""

docs/source/pjrpc/testing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ Look at the following test example:
4444
assert result == 2
4545
4646
pjrpc_aiohttp_mocker.replace(
47-
'http://localhost/api/v1', 'sum', error=pjrpc.exc.JsonRpcError(code=1, message='error', data='oops'),
47+
'http://localhost/api/v1', 'sum', error=pjrpc.client.exceptions.JsonRpcError(code=1, message='error', data='oops'),
4848
)
49-
with pytest.raises(pjrpc.exc.JsonRpcError) as exc_info:
49+
with pytest.raises(pjrpc.client.exceptions.JsonRpcError) as exc_info:
5050
await client.proxy.sum(a=1, b=1)
5151
52-
assert exc_info.type is pjrpc.exc.JsonRpcError
52+
assert exc_info.type is pjrpc.client.exceptions.JsonRpcError
5353
assert exc_info.value.code == 1
5454
assert exc_info.value.message == 'error'
5555
assert exc_info.value.data == 'oops'

docs/source/pjrpc/webui.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ using flask web framework:
8686
id: UserId
8787
8888
89-
class AlreadyExistsError(pjrpc.exc.TypedError):
89+
class AlreadyExistsError(pjrpc.server.exceptions.TypedError):
9090
"""
9191
User already registered error.
9292
"""
@@ -95,7 +95,7 @@ using flask web framework:
9595
MESSAGE = "user already exists"
9696
9797
98-
class NotFoundError(pjrpc.exc.TypedError):
98+
class NotFoundError(pjrpc.server.exceptions.TypedError):
9999
"""
100100
User not found error.
101101
"""

examples/aiohttp_pytest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ async def test_using_fixture(pjrpc_aiohttp_mocker):
1515
assert result == 2
1616

1717
pjrpc_aiohttp_mocker.replace(
18-
'http://localhost/api/v1', 'sum', error=pjrpc.exc.JsonRpcError(code=1, message='error', data='oops'),
18+
'http://localhost/api/v1',
19+
'sum',
20+
error=pjrpc.client.exceptions.JsonRpcError(code=1, message='error', data='oops'),
1921
)
20-
with pytest.raises(pjrpc.exc.JsonRpcError) as exc_info:
22+
with pytest.raises(pjrpc.client.exceptions.JsonRpcError) as exc_info:
2123
await client.proxy.sum(a=1, b=1)
2224

23-
assert exc_info.type is pjrpc.exc.JsonRpcError
25+
assert exc_info.type is pjrpc.client.exceptions.JsonRpcError
2426
assert exc_info.value.code == 1
2527
assert exc_info.value.message == 'error'
2628
assert exc_info.value.data == 'oops'

examples/multiple_clients.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pjrpc.client.backend import requests as jrpc_client
55

66

7-
class ErrorV1(pjrpc.exc.TypedError, base=True):
7+
class ErrorV1(pjrpc.client.exceptions.TypedError, base=True):
88
pass
99

1010

@@ -13,7 +13,7 @@ class PermissionDenied(ErrorV1):
1313
MESSAGE: ClassVar[str] = 'permission denied'
1414

1515

16-
class ErrorV2(pjrpc.exc.TypedError, base=True):
16+
class ErrorV2(pjrpc.client.exceptions.TypedError, base=True):
1717
pass
1818

1919

examples/openapi_aiohttp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class UserOut(UserIn):
6767
id: UserId
6868

6969

70-
class AlreadyExistsError(pjrpc.exc.TypedError):
70+
class AlreadyExistsError(pjrpc.server.exceptions.TypedError):
7171
"""
7272
User already registered error.
7373
"""
@@ -76,7 +76,7 @@ class AlreadyExistsError(pjrpc.exc.TypedError):
7676
MESSAGE = "user already exists"
7777

7878

79-
class NotFoundError(pjrpc.exc.TypedError):
79+
class NotFoundError(pjrpc.server.exceptions.TypedError):
8080
"""
8181
User not found error.
8282
"""

examples/openapi_aiohttp_subendpoints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
import pjrpc.server.specs.extractors.pydantic
99
import pjrpc.server.specs.openapi.ui
10-
from pjrpc.common.exceptions import MethodNotFoundError
10+
from pjrpc.server.exceptions import MethodNotFoundError
1111
from pjrpc.server.integration import aiohttp as integration
1212
from pjrpc.server.specs import extractors, openapi, openrpc
1313
from pjrpc.server.validators import pydantic as validators
1414

1515

16-
class AlreadyExistsError(pjrpc.exc.TypedError):
16+
class AlreadyExistsError(pjrpc.server.exceptions.TypedError):
1717
"""
1818
User already registered error.
1919
"""

0 commit comments

Comments
 (0)