Added checks in prettifyResponseBody for when there's no response body
This commit is contained in:
parent
0cd3ad940a
commit
b57c6a9136
3 changed files with 14 additions and 10 deletions
BIN
docs/Credits.odt
BIN
docs/Credits.odt
Binary file not shown.
|
@ -340,13 +340,20 @@ public class DashboardController implements Initializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prettifyResponseBody(RestaurantResponse response) {
|
private void prettifyResponseBody(RestaurantResponse response) {
|
||||||
String type = response.getMediaType().toString();
|
String type;
|
||||||
// Selects only the part preceding the ';', skipping the character encoding
|
|
||||||
type = type.split(";")[0];
|
if (response.getMediaType() != null)
|
||||||
|
type = response.getMediaType().toString();
|
||||||
|
else
|
||||||
|
type = null;
|
||||||
|
|
||||||
String responseBody = response.getBody();
|
String responseBody = response.getBody();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
|
// Selects only the part preceding the ';', skipping the character encoding
|
||||||
|
type = type.split(";")[0];
|
||||||
|
|
||||||
switch (type.toLowerCase()) {
|
switch (type.toLowerCase()) {
|
||||||
case "application/json":
|
case "application/json":
|
||||||
responseType.setText("JSON");
|
responseType.setText("JSON");
|
||||||
|
@ -366,7 +373,8 @@ public class DashboardController implements Initializable {
|
||||||
responseArea.setText(responseBody);
|
responseArea.setText(responseBody);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
response.setBody("No body found in the response.");
|
responseType.setText("NONE");
|
||||||
|
responseArea.setText("No body found in the response.");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
snackBar.show("Response could not be parsed.", 5000);
|
snackBar.show("Response could not be parsed.", 5000);
|
||||||
|
|
|
@ -223,7 +223,8 @@
|
||||||
</JFXButton>
|
</JFXButton>
|
||||||
</children>
|
</children>
|
||||||
</VBox>
|
</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>
|
<children>
|
||||||
<Label text="Enter an address, select a method and hit send."
|
<Label text="Enter an address, select a method and hit send."
|
||||||
textFill="WHITE">
|
textFill="WHITE">
|
||||||
|
@ -231,11 +232,6 @@
|
||||||
<Font size="32.0" />
|
<Font size="32.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Label text="🚀" textFill="#0093ff">
|
|
||||||
<font>
|
|
||||||
<Font size="43.0"/>
|
|
||||||
</font>
|
|
||||||
</Label>
|
|
||||||
</children>
|
</children>
|
||||||
</VBox>
|
</VBox>
|
||||||
<VBox fx:id="errorLayer" alignment="CENTER" layoutX="10.0" layoutY="10.0" prefHeight="200.0" prefWidth="100.0" visible="false">
|
<VBox fx:id="errorLayer" alignment="CENTER" layoutX="10.0" layoutY="10.0" prefHeight="200.0" prefWidth="100.0" visible="false">
|
||||||
|
|
Loading…
Reference in a new issue