1 /*
2  * Copyright 2002-2017 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 module hunt.stomp.MessagingException;
18 
19 import hunt.stomp.exception;
20 import hunt.stomp.Message;
21 
22 import hunt.Exceptions;
23 
24 
25 /**
26  * The base exception for any failures related to messaging.
27  *
28  * @author Mark Fisher
29  * @author Gary Russell
30  * @since 4.0
31  */
32 
33 class MessagingException : NestedRuntimeException {
34 	
35 	private MessageBase failedMessage;
36 
37 
38 	this(MessageBase message) {
39 		super("");
40 		this.failedMessage = message;
41 	}
42 
43 	this(string description) {
44 		super(description);
45 		this.failedMessage = null;
46 	}
47 
48 	this(string description, Throwable cause) {
49 		super(description, cause);
50 		this.failedMessage = null;
51 	}
52 
53 	this(MessageBase message, string description) {
54 		super(description);
55 		this.failedMessage = message;
56 	}
57 
58 	this(MessageBase message, Throwable cause) {
59 		super(null, cause);
60 		this.failedMessage = message;
61 	}
62 
63 	this(MessageBase message, string description, Throwable cause) {
64 		super(description, cause);
65 		this.failedMessage = message;
66 	}
67 	
68 	MessageBase getFailedMessage() {
69 		return this.failedMessage;
70 	}
71 
72 	override
73 	string toString() {
74 		return super.toString() ~ (this.failedMessage is null ? ""
75 				: (", failedMessage=" ~ (cast(Object)this.failedMessage).toString()));
76 	}
77 
78 }
79 
80 
81 
82 /**
83  * Exception that indicates an error occurred during message handling.
84  *
85  * @author Mark Fisher
86  * @since 4.0
87  */
88 
89 class MessageHandlingException : MessagingException {
90 
91 	this(MessageBase failedMessage) {
92 		super(failedMessage);
93 	}
94 
95 	this(MessageBase message, string description) {
96 		super(message, description);
97 	}
98 
99 	this(MessageBase failedMessage, Throwable cause) {
100 		super(failedMessage, cause);
101 	}
102 
103 	this(MessageBase message, string description, Throwable cause) {
104 		super(message, description, cause);
105 	}
106 
107 }
108 
109 
110 /**
111  * Exception that indicates an error occurred during message delivery.
112  *
113  * @author Mark Fisher
114  * @since 4.0
115  */
116 
117 class MessageDeliveryException : MessagingException {
118 
119 	this(string description) {
120 		super(description);
121 	}
122 
123 	this(MessageBase undeliveredMessage) {
124 		super(undeliveredMessage);
125 	}
126 
127 	this(MessageBase undeliveredMessage, string description) {
128 		super(undeliveredMessage, description);
129 	}
130 
131 	this(MessageBase message, Throwable cause) {
132 		super(message, cause);
133 	}
134 
135 	this(MessageBase undeliveredMessage, string description, Throwable cause) {
136 		super(undeliveredMessage, description, cause);
137 	}
138 
139 }
140 
141 
142 /**
143  * {@link MessagingException} thrown when a session is missing.
144  *
145  * @author Rossen Stoyanchev
146  * @since 4.0
147  */
148 
149 class MissingSessionUserException : MessagingException {
150 
151 	this(MessageBase message) {
152 		super(message, "No \"user\" header in message");
153 	}
154 
155 }
156 
157 
158 class MessageConversionException : MessagingException {
159 
160 	this(string description) {
161 		super(description);
162 	}
163 
164 	this(string description, Throwable cause) {
165 		super(description, cause);
166 	}
167 
168 	this(MessageBase failedMessage, string description) {
169 		super(failedMessage, description);
170 	}
171 
172 	this(MessageBase failedMessage, string description, Throwable cause) {
173 		super(failedMessage, description, cause);
174 	}
175 
176 }