Skip to content

Commit 3b9ded0

Browse files
committed
minor fix
1 parent a818f03 commit 3b9ded0

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,17 @@ private String parseResponse(String responseBody) throws JsonProcessingException
135135
String result = "";
136136
JsonNode node = new ObjectMapper().readTree(responseBody);
137137
JsonNode errorNode = node.get("json").get("errors").get(0);
138-
for (JsonNode child : errorNode) {
139-
result = result + child.toString().replaceAll("\"|null", "") + "<br>";
140-
}
141-
if (result.length() == 0) {
138+
if (errorNode != null) {
139+
for (JsonNode child : errorNode) {
140+
result = result + child.toString().replaceAll("\"|null", "") + "<br>";
141+
}
142+
return result;
143+
} else {
142144
if (node.get("json").get("data") != null && node.get("json").get("data").get("url") != null)
143145
return "Post submitted successfully <a href=\"" + node.get("json").get("data").get("url").asText() + "\"> check it out </a>";
144146
else
145147
return "Error Occurred";
146148
}
147-
return result;
148149
}
149150

150151
public void setRedditRestTemplate(OAuth2RestTemplate redditRestTemplate) {

0 commit comments

Comments
 (0)