-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
예외 반환 로직 수정
- Loading branch information
Showing
5 changed files
with
33 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
package com.dnd.snappy.common.dto; | ||
|
||
import com.dnd.snappy.common.error.ErrorCodeInterface; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
public record ResponseDto<T>( | ||
boolean success, | ||
int status, | ||
T data, | ||
ErrorResponseDto error | ||
@JsonInclude(JsonInclude.Include.NON_NULL) ErrorResponseDto error | ||
) { | ||
|
||
public static <T> ResponseEntity<ResponseDto<T>> ok(T data) { | ||
ResponseDto<T> responseDto = new ResponseDto<>(true, data, null); | ||
return ResponseEntity | ||
.ok(responseDto); | ||
.ok(new ResponseDto<>(HttpStatus.OK.value(), data, null)); | ||
} | ||
|
||
public static <T> ResponseEntity<ResponseDto<?>> ok() { | ||
ResponseDto<T> responseDto = new ResponseDto<>(true, null, null); | ||
return ResponseEntity | ||
.ok(responseDto); | ||
.ok(new ResponseDto<>(HttpStatus.OK.value(), null, null)); | ||
} | ||
|
||
public static <T> ResponseEntity<ResponseDto<T>> created(T data) { | ||
ResponseDto<T> responseDto = new ResponseDto<>(true, data, null); | ||
ResponseDto<T> responseDto = new ResponseDto<>(HttpStatus.CREATED.value(), data, null); | ||
return ResponseEntity | ||
.status(HttpStatus.CREATED) | ||
.body(responseDto); | ||
} | ||
|
||
public static ResponseEntity<ResponseDto<?>> fail(ErrorCodeInterface errorCode) { | ||
ResponseDto<?> responseDto = new ResponseDto<>(false, null, ErrorResponseDto.from(errorCode)); | ||
ResponseDto<?> responseDto = new ResponseDto<>(errorCode.getStatus().value(), null, ErrorResponseDto.from(errorCode)); | ||
return ResponseEntity | ||
.status(errorCode.getStatus()) | ||
.body(responseDto); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.