Skip to content

Commit 9b27cd3

Browse files
authored
Merge pull request #90 from bjornharvold/main
fix(#89): 🐛 removed incorrect casting to MailerSendException
2 parents 58a1b87 + 97a97d8 commit 9b27cd3

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/main/java/com/mailersend/sdk/MailerSendApi.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public <T extends MailerSendResponse> T getRequest(String endpoint, Class<T> res
8383

8484
} catch (IOException | InterruptedException e) {
8585

86-
MailerSendException ex = (MailerSendException) e;
87-
86+
MailerSendException ex = new MailerSendException(e.getMessage());
87+
ex.setStackTrace(e.getStackTrace());
8888
throw ex;
8989
}
9090

@@ -126,8 +126,8 @@ public <T extends MailerSendResponse> T postRequest(String endpoint, String requ
126126

127127
} catch (IOException | InterruptedException e) {
128128

129-
MailerSendException ex = (MailerSendException) e;
130-
129+
MailerSendException ex = new MailerSendException(e.getMessage());
130+
ex.setStackTrace(e.getStackTrace());
131131
throw ex;
132132
}
133133

@@ -159,8 +159,8 @@ public <T extends MailerSendResponse> T deleteRequest(String endpoint, Class<T>
159159

160160
} catch (IOException | InterruptedException e) {
161161

162-
MailerSendException ex = (MailerSendException) e;
163-
162+
MailerSendException ex = new MailerSendException(e.getMessage());
163+
ex.setStackTrace(e.getStackTrace());
164164
throw ex;
165165
}
166166

@@ -192,9 +192,8 @@ public <T extends MailerSendResponse> T deleteRequest(String endpoint, String re
192192
responseObject = this.client.send(request, BodyHandlers.ofString());
193193

194194
} catch (IOException | InterruptedException e) {
195-
196-
MailerSendException ex = (MailerSendException) e;
197-
195+
MailerSendException ex = new MailerSendException(e.getMessage());
196+
ex.setStackTrace(e.getStackTrace());
198197
throw ex;
199198
}
200199

@@ -230,9 +229,8 @@ public <T extends MailerSendResponse> T putRequest(String endpoint, String reque
230229
responseObject = this.client.send(request, BodyHandlers.ofString());
231230

232231
} catch (IOException | InterruptedException e) {
233-
234-
MailerSendException ex = (MailerSendException) e;
235-
232+
MailerSendException ex = new MailerSendException(e.getMessage());
233+
ex.setStackTrace(e.getStackTrace());
236234
throw ex;
237235
}
238236

@@ -246,7 +244,7 @@ public <T extends MailerSendResponse> T putRequest(String endpoint, String reque
246244
* @param responseObject The HttpResponse object of the request
247245
* @param responseClass The class of the response object
248246
* @return T
249-
* @throws MailerSendException
247+
* @throws MailerSendException Wraps any errors in this exception.
250248
*/
251249
private <T extends MailerSendResponse> T handleApiResponse(HttpResponse<String> responseObject, Class<T> responseClass) throws MailerSendException {
252250

@@ -307,9 +305,8 @@ private <T extends MailerSendResponse> T handleApiResponse(HttpResponse<String>
307305

308306
response = responseClass.getDeclaredConstructor().newInstance();
309307
} catch (Exception e) {
310-
311-
MailerSendException ex = (MailerSendException) e;
312-
308+
MailerSendException ex = new MailerSendException(e.getMessage());
309+
ex.setStackTrace(e.getStackTrace());
313310
throw ex;
314311
}
315312
}

0 commit comments

Comments
 (0)