-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathErrorResponse.java
More file actions
29 lines (25 loc) · 917 Bytes
/
ErrorResponse.java
File metadata and controls
29 lines (25 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.cha.carrotApi.DTO.exception;
import com.cha.carrotApi.exception.ErrorCode;
import lombok.Builder;
import lombok.Getter;
import org.springframework.http.ResponseEntity;
import java.time.LocalDateTime;
@Getter
@Builder
public class ErrorResponse {
private final LocalDateTime timestamp = LocalDateTime.now();
private final int status;
private final String error;
private final String code;
private final String message;
public static ResponseEntity<ErrorResponse> toResponseEntity(ErrorCode errorCode) {
return ResponseEntity
.status(errorCode.getHttpStatus())
.body(ErrorResponse.builder()
.status(errorCode.getHttpStatus().value())
.error(errorCode.getHttpStatus().name())
.message(errorCode.getMessage())
.build()
);
}
}