wtekiela / opensub4j

Java library for communicating with opensubtitles.org XML-RPC API
Other
47 stars 19 forks source link

properly handle responses other than 200, fixes #26 #28

Closed wtekiela closed 3 years ago

wtekiela commented 3 years ago

Fix for getting ClassCastException while downloading subtitles for an user whose daily limit is reached. In this case, the response contains boolean in data field:

Response: {seconds=0.004, data=false, status=407 Download limit reached}

NOTE: Fix for this bug introduces API incompatibility, ListResponse will now return Optional<List<T>> instead of List<T>.

diff --git a/src/main/java/com/github/wtekiela/opensub4j/response/ListResponse.java b/src/main/java/com/github/wtekiela/opensub4j/response/ListResponse.java
index 7718982..4433e7f 100644
--- a/src/main/java/com/github/wtekiela/opensub4j/response/ListResponse.java
+++ b/src/main/java/com/github/wtekiela/opensub4j/response/ListResponse.java
@@ -14,13 +14,14 @@ package com.github.wtekiela.opensub4j.response;

 import java.util.List;
 import java.util.Objects;
+import java.util.Optional;

 public class ListResponse<T> extends Response {

     @OpenSubtitlesApiSpec(fieldName = "data")
-    private List<T> data;
+    private Optional<List<T>> data;

-    public List<T> getData() {
+    public Optional<List<T>> getData() {
         return data;
     }
sonarcloud[bot] commented 3 years ago

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

78.6% 78.6% Coverage
0.0% 0.0% Duplication