Skip to content

Commit 4ee7bfb

Browse files
committed
Mapper: Modify exception messages to clarify what's the potential issue.
1 parent bf12515 commit 4ee7bfb

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

  • src/main/java/io/github/hikingc/matrixsdk/services/utils

‎src/main/java/io/github/hikingc/matrixsdk/services/utils/Mapper.java‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static String writeValueAsString(Object object) {
5858
public static String getStringValueOfAJsonKey(String json, String key) {
5959
JsonNode tree = INSTANCE.readTree(json);
6060
if (tree == null || tree.isMissingNode()) {
61-
throw new MatrixIOException("Empty or malformed server response");
61+
throw new MatrixIOException("Empty or malformed server response.");
6262
}
6363
JsonNode value = tree.get(key);
6464
if (value == null) {
@@ -136,9 +136,12 @@ public static <T> T getObjectFromString(@Nullable String responseBody, @Nullable
136136
return INSTANCE.readValue(responseBody, type);
137137
} catch (DatabindException e) {
138138
throw new MatrixIOException(
139-
"Server didn't return required fields specified by the protocol", e);
139+
"Unable to deserialize server response into expected structure", e);
140140
} catch (StreamReadException e) {
141-
throw new MatrixIOException("Server responded with invalid response", e);
141+
throw new MatrixIOException("Unable to process invalid response.", e);
142+
} catch (JacksonException e) {
143+
throw new MatrixIOException(
144+
"A failure has failed attempting to process a response object.", e);
142145
}
143146
}
144147

@@ -158,9 +161,12 @@ public static <T> T getObjectFromString(
158161
return INSTANCE.readValue(responseBody, type);
159162
} catch (DatabindException e) {
160163
throw new MatrixIOException(
161-
"Server didn't return required fields specified by the protocol", e);
164+
"Unable to deserialize server response into expected structure", e);
162165
} catch (StreamReadException e) {
163-
throw new MatrixIOException("Server responded with invalid response", e);
166+
throw new MatrixIOException("Unable to process invalid response.", e);
167+
} catch (JacksonException e) {
168+
throw new MatrixIOException(
169+
"A failure has failed attempting to process a response object.", e);
164170
}
165171
}
166172
}

0 commit comments

Comments
 (0)