Skip to content

Commit 2097a63

Browse files
author
DanielePalaia
committed
adding user-defined exception
1 parent d4e4ccf commit 2097a63

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

examples/getting_started/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def main() -> None:
2323
QueueSpecification(name=queue_name, queue_type=QueueType.quorum, arguments={})
2424
)
2525

26-
binding_exchange_queue_path = management.bind(
26+
management.bind(
2727
BindingSpecification(
2828
source_exchange=exchange_name,
2929
destination_queue=queue_name,
@@ -49,7 +49,7 @@ def main() -> None:
4949
publisher.close()
5050
"""
5151

52-
management.unbind(binding_exchange_queue_path)
52+
# management.unbind(binding_exchange_queue_path)
5353

5454
"""
5555
management.purge_queue(queue_info.name)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class ValidationCodeException(Exception):
2+
# Constructor or Initializer
3+
def __init__(self, msg: str):
4+
self.msg = msg
5+
6+
# __str__ is to print() the value
7+
def __str__(self) -> str:
8+
return repr(self.msg)

rabbitmq_amqp_python_client/management.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ExchangeSpecification,
2222
QueueSpecification,
2323
)
24+
from .exceptions import ValidationCodeException
2425
from .options import ReceiverOption, SenderOption
2526

2627

@@ -131,8 +132,8 @@ def declare_queue(
131132
path,
132133
CommonValues.command_put.value,
133134
[
135+
CommonValues.response_code_200.value,
134136
CommonValues.response_code_201.value,
135-
CommonValues.response_code_204.value,
136137
CommonValues.response_code_409.value,
137138
],
138139
)
@@ -171,13 +172,15 @@ def _validate_reponse_code(
171172
print("response_code received: " + str(response_code))
172173
if response_code == CommonValues.response_code_409.value:
173174
# TODO replace with a new defined Exception
174-
raise Exception("ErrPreconditionFailed")
175+
raise ValidationCodeException("ErrPreconditionFailed")
175176

176177
for code in expected_response_codes:
177178
if code == response_code:
178179
return None
179180

180-
raise Exception("wrong response code received")
181+
raise ValidationCodeException(
182+
"wrong response code received: " + str(response_code)
183+
)
181184

182185
# TODO
183186
def bind(self, bind_specification: BindingSpecification) -> str:

0 commit comments

Comments
 (0)