1 module dutils.message.exceptions;
2 
3 import std.conv : to;
4 import core.time : Duration;
5 
6 class ConnectException : Exception {
7   this(string host, int port, string username, string file = __FILE__, size_t line = __LINE__) {
8     super("Unable to connect to AMQP 0-9-1 service at " ~ host ~ ":" ~ port.to!string ~ " with username " ~ username,
9         file, line);
10   }
11 }
12 
13 class PublishException : Exception {
14   this(string type, string queueName, string file = __FILE__, size_t line = __LINE__) {
15     super("Failed to publish " ~ type ~ " message to queue \"" ~ queueName ~ "\" on  0-9-1 service",
16         file, line);
17   }
18 }
19 
20 class DeclareQueueException : Exception {
21   this(string queueName, string file = __FILE__, size_t line = __LINE__) {
22     super("Failed to declare queue \"" ~ queueName ~ "\" on  0-9-1 service", file, line);
23   }
24 }
25 
26 class SubscribeQueueException : Exception {
27   this(string queueName, Exception originalException, string file = __FILE__, size_t line = __LINE__) {
28     super("Failed to subscribe to queue \"" ~ queueName
29         ~ "\" on  0-9-1 service. Original exception: " ~ originalException.message.to!string,
30         file, line);
31   }
32 }
33 
34 class RequestException : Exception {
35   this(string type, string queueName, string file = __FILE__, size_t line = __LINE__) {
36     super("Request " ~ type ~ " on queue \"" ~ queueName ~ "\" failed on  0-9-1 service",
37         file, line);
38   }
39 }
40 
41 class TimeoutRequestException : Exception {
42   this(string type, Duration expiration, string queueName,
43       string file = __FILE__, size_t line = __LINE__) {
44     super("Request " ~ type ~ " on queue \"" ~ queueName ~ "\" reached the timeout limit of " ~ expiration.toString()
45         ~ " on  0-9-1 service", file, line);
46   }
47 }
48 
49 class MessageBodyException : Exception {
50   this(string type, string file = __FILE__, size_t line = __LINE__) {
51     super("Failed to parse message body for message of type " ~ type, file, line);
52   }
53 }
54 
55 class MessageHeaderException : Exception {
56   this(string headerName, string type, string file = __FILE__, size_t line = __LINE__) {
57     super("Failed to parse message header " ~ headerName ~ " for message of type " ~ type,
58         file, line);
59   }
60 }
61 
62 class TypeMismatchException : Exception {
63   this(string expectedType, string type, string file = __FILE__, size_t line = __LINE__) {
64     super("Expected type " ~ expectedType ~ " but got " ~ type, file, line);
65   }
66 }