Skip to content

Commit 17f4d56

Browse files
committed
Added helper for blockscore error
1 parent 50a803f commit 17f4d56

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/main/java/com/blockscore/models/error/BlockscoreError.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import org.jetbrains.annotations.NotNull;
5+
import org.jetbrains.annotations.Nullable;
6+
import retrofit.RetrofitError;
57

68
/**
79
* Blockscore Error model.
@@ -12,6 +14,21 @@ public class BlockscoreError {
1214
@JsonProperty("error")
1315
private RequestError mRequestError;
1416

17+
/**
18+
* Converts a Retrofit Error into a Blockscore Error.
19+
* @param cause Retrofit error to convert.
20+
* @return Blockscore Error
21+
*/
22+
@Nullable
23+
public static BlockscoreError getBlockscoreError(@NotNull final RetrofitError cause) {
24+
Object rawError = cause.getBodyAs(BlockscoreError.class);
25+
if (rawError instanceof BlockscoreError) {
26+
return (BlockscoreError) rawError;
27+
} else {
28+
return null;
29+
}
30+
}
31+
1532
/**
1633
* Returns the error details.
1734
* @return Error details.

0 commit comments

Comments
 (0)