-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from LikeLion-12th-SKHU/develop
Develop -> main push
- Loading branch information
Showing
11 changed files
with
140 additions
and
66 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/java/org/likelion/likelion_12th_team05/common/EntityFinder.java
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.likelion.likelion_12th_team05.common; | ||
|
||
import org.likelion.likelion_12th_team05.common.error.ErrorCode; | ||
import org.likelion.likelion_12th_team05.common.exception.NotFoundException; | ||
|
||
import java.util.Optional; | ||
|
||
public class EntityFinder { | ||
|
||
// ์ํฐํฐ not found ์ฒ๋ฆฌ | ||
public static <T> T findByIdOrThrow(Optional<T> optionalEntity, ErrorCode errorCode) { | ||
return optionalEntity.orElseThrow(() -> | ||
new NotFoundException(errorCode, errorCode.getMessage())); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/likelion/likelion_12th_team05/common/advice/CustomExceptionAdvice.java
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.likelion.likelion_12th_team05.common.advice; | ||
|
||
import org.likelion.likelion_12th_team05.common.exception.NotFoundException; | ||
import org.likelion.likelion_12th_team05.config.ApiResponseTemplate; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
@ControllerAdvice | ||
public class CustomExceptionAdvice { | ||
|
||
// ์ํฐํฐ not found ์๋ฌ ์ฒ๋ฆฌ ํธ๋ค๋ฌ | ||
@ExceptionHandler(NotFoundException.class) | ||
public ResponseEntity<ApiResponseTemplate<Void>> handleNotFoundException(NotFoundException ex) { | ||
ApiResponseTemplate<Void> errorResponse = ApiResponseTemplate.errorResponse(ex.getErrorCode()); | ||
return new ResponseEntity<>(errorResponse, HttpStatus.NOT_FOUND); | ||
} | ||
|
||
} |
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
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
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.