Last active
September 28, 2019 07:29
-
-
Save hosseiniSeyRo/13c447d7738e4252ac6d1c31d00fa610 to your computer and use it in GitHub Desktop.
ResponseWrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ResponseWrapper<T> { | |
@NonNull | |
private Status status; | |
@Nullable | |
private T data; | |
@Nullable | |
private Integer errorCode; | |
@Nullable | |
private String errorMessage; | |
private ResponseWrapper(@NonNull Status status, @Nullable T data, @Nullable Integer errorCode, @Nullable String errorMessage) { | |
this.status = status; | |
this.data = data; | |
this.errorCode = errorCode; | |
this.errorMessage = errorMessage; | |
} | |
public static ResponseWrapper loading() { | |
return new ResponseWrapper(Status.LOADING, null, null, null); | |
} | |
public ResponseWrapper success(@NonNull T data) { | |
return new ResponseWrapper(Status.SUCCESS, data, null, null); | |
} | |
public static ResponseWrapper error(@Nullable int errorCode, @NonNull String errorMessage) { | |
return new ResponseWrapper(Status.ERROR, null, errorCode, errorMessage); | |
} | |
private enum Status { | |
LOADING, | |
SUCCESS, | |
ERROR | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment