Skip to content

Commit ae1a828

Browse files
BullSharkCreativeCodeCat
authored andcommitted
Exception handling
Fixed a crash that would occur when valid json was not given by the api
1 parent b6f4dbd commit ae1a828

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/java/jrobo/Leet.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.gson.Gson;
2222
import com.google.gson.GsonBuilder;
23+
import com.google.gson.JsonSyntaxException;
2324
import java.io.IOException;
2425
import java.net.URI;
2526
import java.util.Arrays;
@@ -237,9 +238,10 @@ public String getFormattedResult(final boolean HAS_COLORS) {
237238
gson = new GsonBuilder().setPrettyPrinting().create();
238239
RESULTS = gson.fromJson(this.getJson(), LeetJsonItem[].class);
239240

240-
} catch (IllegalStateException | NullPointerException ex) {
241+
} catch (IllegalStateException | NullPointerException | JsonSyntaxException ex) {
241242
Logger.getLogger(Leet.class.getName()).log(Level.SEVERE, null, ex);
242-
return "";
243+
json = "{ \"data\": \"Unable to retrieve Torrent json data\" }";
244+
return json;
243245
}
244246

245247
String output = "";

0 commit comments

Comments
 (0)