Added checks in prettifyResponseBody for when there's no response body

This commit is contained in:
Rohit Awate 2018-04-23 11:55:19 +05:30
parent 0cd3ad940a
commit b57c6a9136
No known key found for this signature in database
GPG key ID: 9C04E52F6B625A85
3 changed files with 14 additions and 10 deletions

Binary file not shown.

View file

@ -340,13 +340,20 @@ public class DashboardController implements Initializable {
}
private void prettifyResponseBody(RestaurantResponse response) {
String type = response.getMediaType().toString();
// Selects only the part preceding the ';', skipping the character encoding
type = type.split(";")[0];
String type;
if (response.getMediaType() != null)
type = response.getMediaType().toString();
else
type = null;
String responseBody = response.getBody();
try {
if (type != null) {
// Selects only the part preceding the ';', skipping the character encoding
type = type.split(";")[0];
switch (type.toLowerCase()) {
case "application/json":
responseType.setText("JSON");
@ -366,7 +373,8 @@ public class DashboardController implements Initializable {
responseArea.setText(responseBody);
}
} else {
response.setBody("No body found in the response.");
responseType.setText("NONE");
responseArea.setText("No body found in the response.");
}
} catch (Exception e) {
snackBar.show("Response could not be parsed.", 5000);

View file

@ -223,7 +223,8 @@
</JFXButton>
</children>
</VBox>
<VBox fx:id="promptLayer" alignment="CENTER" prefHeight="200.0" prefWidth="100.0" visible="false">
<VBox fx:id="promptLayer" alignment="CENTER" prefHeight="200.0"
prefWidth="100.0">
<children>
<Label text="Enter an address, select a method and hit send."
textFill="WHITE">
@ -231,11 +232,6 @@
<Font size="32.0" />
</font>
</Label>
<Label text="🚀" textFill="#0093ff">
<font>
<Font size="43.0"/>
</font>
</Label>
</children>
</VBox>
<VBox fx:id="errorLayer" alignment="CENTER" layoutX="10.0" layoutY="10.0" prefHeight="200.0" prefWidth="100.0" visible="false">