inisialisasi kembali

This commit is contained in:
tias
2024-06-15 17:04:28 +07:00
parent 3e97011f66
commit 0f99b87e47
151 changed files with 9074 additions and 224 deletions
@@ -0,0 +1,32 @@
package org.sadigit.control.errorhandlers;
// import java.util.LinkedHashMap;
import java.util.Map;
import java.util.LinkedHashMap;
import org.sadigit.control.exception.CustomException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
@Provider
public class CustomExceptionHandler implements ExceptionMapper<CustomException>{
@Override
public Response toResponse(CustomException exception) {
if (exception.getCustomErrorStructure() != null) {
return Response.status(Status.OK).entity(exception.getCustomErrorStructure()).build();
} else {
Map<String, Object> response = new LinkedHashMap<>();
exception.printStackTrace();
response.put("status", false);
response.put("title", "Terjadi Kesalahan");
response.put("message", exception.getMessage());
return Response.status(Status.OK).entity(response).build();
}
}
}
@@ -0,0 +1,27 @@
package org.sadigit.control.errorhandlers;
import java.util.Map;
import org.sadigit.control.exception.GetDataGarduV2Exception;
import org.sadigit.model.response.base.ResponseModelGarduV2;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
@Provider
public class GetDataGarduV2Handler implements ExceptionMapper<GetDataGarduV2Exception>{
@Override
public Response toResponse(GetDataGarduV2Exception exception) {
ResponseModelGarduV2<Map<String,Object>> response = new ResponseModelGarduV2<>();
response.setP_return(Map.of(
"errorcode", exception.getErrorCode(),
"info", exception.getMessage()
));
return Response.status(Response.Status.OK).entity(response).build();
}
}
@@ -0,0 +1,23 @@
package org.sadigit.control.exception;
import lombok.Getter;
@Getter
public class CustomException extends RuntimeException{
private static final long serialVersionUID = 1L;
private Object customErrorStructure;
public CustomException() {
super();
}
public CustomException(String msg) {
super(msg);
}
public CustomException(String msg, Object customErrorStructure) {
super();
this.customErrorStructure = customErrorStructure;
}
}
@@ -0,0 +1,20 @@
package org.sadigit.control.exception;
import lombok.Getter;
@Getter
public class GetDataGarduV2Exception extends RuntimeException{
private static final long serialVersionUID = 1L;
private String errorCode;
public GetDataGarduV2Exception(String errorCode) {
super();
this.errorCode = errorCode;
}
public GetDataGarduV2Exception(String errorCode, String msg) {
super(msg);
this.errorCode = errorCode;
}
}