Skip to content

Instantly share code, notes, and snippets.

@hosseiniSeyRo
Last active September 28, 2019 07:29
Show Gist options
  • Save hosseiniSeyRo/13c447d7738e4252ac6d1c31d00fa610 to your computer and use it in GitHub Desktop.
Save hosseiniSeyRo/13c447d7738e4252ac6d1c31d00fa610 to your computer and use it in GitHub Desktop.
ResponseWrapper
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