46 lines
776 B
Java
46 lines
776 B
Java
package be.jeffcheasey88.todo.model;
|
|
|
|
import dev.peerat.framework.Context;
|
|
import dev.peerat.framework.HttpWriter;
|
|
|
|
public class Result<E>{
|
|
|
|
private E element;
|
|
private int errorCode;
|
|
private String error;
|
|
|
|
public Result(E element){
|
|
this.element = element;
|
|
}
|
|
|
|
public Result(int errorCode, String error){
|
|
this.errorCode = errorCode;
|
|
this.error = error;
|
|
}
|
|
|
|
public void send(Context context, HttpWriter writer) throws Exception{
|
|
if(success()) context.response(200);
|
|
else{
|
|
context.response(errorCode);
|
|
writer.write(error);
|
|
}
|
|
}
|
|
|
|
public boolean success(){
|
|
return error == null;
|
|
}
|
|
|
|
public E getElement(){
|
|
return this.element;
|
|
}
|
|
|
|
public int getErrorCode(){
|
|
return this.errorCode;
|
|
}
|
|
|
|
public String getError(){
|
|
return this.error;
|
|
}
|
|
|
|
}
|