Skip to content

Commit

Permalink
feat: 커스텀 예외 및 에러 코드/응답 구현 (#19)
Browse files Browse the repository at this point in the history
* feat: 에러 코드 구현

* feat: 커스텀 예외 구현

* feat: 예외 응답 구현
  • Loading branch information
uwoobeat authored and kdomo committed Nov 28, 2023
1 parent 1ea9ad9 commit f19a1e3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/depromeet/global/error/ErrorResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.depromeet.global.error;

import java.time.LocalDateTime;

import org.springframework.http.HttpStatus;

public record ErrorResponse(
int status,
String message,
LocalDateTime timestamp
) {

public static ErrorResponse of(HttpStatus status, String message) {
return new ErrorResponse(status.value(), message, LocalDateTime.now());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.depromeet.global.error.exception;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class CustomException extends RuntimeException {

private final ErrorCode errorCode;
}
17 changes: 17 additions & 0 deletions src/main/java/com/depromeet/global/error/exception/ErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.depromeet.global.error.exception;

import org.springframework.http.HttpStatus;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ErrorCode {

SAMPLE_ERROR(HttpStatus.BAD_REQUEST, "Sample Error Message"),
;

private final HttpStatus status;
private final String message;
}

0 comments on commit f19a1e3

Please sign in to comment.