From 5992cd6fff8116085b190ade88693b802142d99f Mon Sep 17 00:00:00 2001 From: kang Date: Tue, 4 Jun 2024 23:54:04 +0900 Subject: [PATCH 1/4] feat: setting error response dto --- .../ddanzi/common/response/ErrorResponse.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/co/orange/ddanzi/common/response/ErrorResponse.java diff --git a/src/main/java/co/orange/ddanzi/common/response/ErrorResponse.java b/src/main/java/co/orange/ddanzi/common/response/ErrorResponse.java new file mode 100644 index 00000000..e01d9c91 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/common/response/ErrorResponse.java @@ -0,0 +1,44 @@ +package co.orange.ddanzi.common.response; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; +import lombok.RequiredArgsConstructor; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +@RequiredArgsConstructor +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ErrorResponse { + + private int status; + private String message; + private LocalDateTime time; + private String path; + private String trace; + private List vaildErrors; + + @Data + @RequiredArgsConstructor + private static class VaildationError { + private final String field; + private final String message; + } + + public void addVaildationError(String field, String message) { + if (Objects.isNull(vaildErrors)){ + vaildErrors = new ArrayList<>(); + } + vaildErrors.add(new VaildationError(field, message)); + } + + public ErrorResponse(int status, String message, String path, LocalDateTime time) { + this.status = status; + this.message = message; + this.path = path; + this.time = time; + } +} From 85d6eb7e26aa450de8c9df9abb952b830f20c436 Mon Sep 17 00:00:00 2001 From: kang Date: Wed, 5 Jun 2024 17:13:30 +0900 Subject: [PATCH 2/4] chore: update gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 37729f58..a0d31a36 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ build/ !**/src/main/**/build/ !**/src/test/**/build/ +### YML ### +application-* + ### STS ### .apt_generated .classpath From dea228042b099b9a77fbe6abc71c0d111e6d46a4 Mon Sep 17 00:00:00 2001 From: kang Date: Wed, 5 Jun 2024 17:13:39 +0900 Subject: [PATCH 3/4] chore: update yml --- src/main/resources/application.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8b137891..ef46c2ad 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1 +1,3 @@ - +spring: + profiles: + active: local \ No newline at end of file From f475dd3573299ae6d357a2b64e58fc2773b89f29 Mon Sep 17 00:00:00 2001 From: kang Date: Sun, 9 Jun 2024 23:22:32 +0900 Subject: [PATCH 4/4] feat: add response msg --- .../orange/ddanzi/common/response/Error.java | 43 +++++++++++++++++++ .../ddanzi/common/response/Success.java | 27 ++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/main/java/co/orange/ddanzi/common/response/Error.java create mode 100644 src/main/java/co/orange/ddanzi/common/response/Success.java diff --git a/src/main/java/co/orange/ddanzi/common/response/Error.java b/src/main/java/co/orange/ddanzi/common/response/Error.java new file mode 100644 index 00000000..660bdfda --- /dev/null +++ b/src/main/java/co/orange/ddanzi/common/response/Error.java @@ -0,0 +1,43 @@ +package co.orange.ddanzi.common.response; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public enum Error { + // Default + ERROR(HttpStatus.BAD_REQUEST, "Request processing failed"), + + // 400 BAD REQUEST + + + // 401 UNAUTHORIZED + + + // 403 Forbidden + + + // 404 NOT FOUND + + + // 405 METHOD_NOT_ALLOWED + + + // 409 CONFLICT + + + + // 500 INTERNAL SERVER ERROR + INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error"), + ; + + private final HttpStatus httpStatus; + private final String message; + + public int getHttpStatusCode() { + return httpStatus.value(); + } +} diff --git a/src/main/java/co/orange/ddanzi/common/response/Success.java b/src/main/java/co/orange/ddanzi/common/response/Success.java new file mode 100644 index 00000000..a5641dd5 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/common/response/Success.java @@ -0,0 +1,27 @@ +package co.orange.ddanzi.common.response; + + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public enum Success { + // Default + SUCCESS(HttpStatus.OK, "Request successfully processed"), + + // 200 OK SUCCESS + + // 201 CREATED + + ; + + private final HttpStatus httpStatus; + private final String message; + + public int getHttpStatusCode() { + return httpStatus.value(); + } +}