File tree 3 files changed +26
-2
lines changed
src/main/java/com/wildbit/java/postmark/client
3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ private void validateResponse(HttpClient.ClientResponse response) throws Postmar
140
140
throw new InvalidAPIKeyException (dataHandler .formatErrorMessage (message ));
141
141
142
142
case 422 :
143
- throw new InvalidMessageException (dataHandler .formatErrorMessage (message ));
143
+ throw new InvalidMessageException (dataHandler .formatErrorMessage (message ), dataHandler . formatErrorCode ( message ) );
144
144
145
145
case 500 :
146
146
throw new InternalServerException (dataHandler .formatErrorMessage (message ));
Original file line number Diff line number Diff line change @@ -70,6 +70,23 @@ public String formatErrorMessage(String data) throws IOException {
70
70
return node .get ("Message" ).textValue ();
71
71
}
72
72
73
+ /**
74
+ * Helper for filtering out error code returned by Postmark in case of HTTP status code 422
75
+ * @param data JSON object as String
76
+ * @return error code
77
+ * @throws IOException in case converting String to Object fails
78
+ */
79
+ public Integer formatErrorCode (String data ) throws IOException {
80
+ JsonNode node = fromJson (data , JsonNode .class );
81
+ JsonNode errorCodeNode = node .get ("ErrorCode" );
82
+
83
+ if (errorCodeNode == null || errorCodeNode .isNull ()) {
84
+ return null ;
85
+ }
86
+
87
+ return errorCodeNode .intValue ();
88
+ }
89
+
73
90
/**
74
91
* Sets data mapper to be strict when making conversion of data to objects.
75
92
* If there is a mismatch between object and String in any other case than letter case,
Original file line number Diff line number Diff line change 5
5
*/
6
6
7
7
public class InvalidMessageException extends PostmarkException {
8
- public InvalidMessageException (String message ) {
8
+ private final Integer errorCode ;
9
+
10
+ public InvalidMessageException (String message , Integer errorCode ) {
9
11
super (message );
12
+ this .errorCode = errorCode ;
13
+ }
14
+
15
+ public Integer getErrorCode () {
16
+ return errorCode ;
10
17
}
11
18
}
12
19
You can’t perform that action at this time.
0 commit comments