-
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.
Browse files
Browse the repository at this point in the history
Feature/#172 error refactor
- Loading branch information
Showing
36 changed files
with
215 additions
and
382 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
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
22 changes: 22 additions & 0 deletions
22
module-api/src/main/java/com/yapp/sharefood/common/error/ErrorResponse.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,22 @@ | ||
package com.yapp.sharefood.common.error; | ||
|
||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@Getter | ||
public class ErrorResponse { | ||
private final String message; | ||
|
||
public ErrorResponse(String message) { | ||
this.message = message; | ||
} | ||
|
||
public static ResponseEntity<ErrorResponse> toResponseEntity(HttpStatus httpStatus, String errorMessage) { | ||
return ResponseEntity | ||
.status(httpStatus) | ||
.body( | ||
new ErrorResponse(errorMessage) | ||
); | ||
} | ||
} |
12 changes: 8 additions & 4 deletions
12
module-api/src/main/java/com/yapp/sharefood/favorite/advice/FavoriteAdviceController.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 |
---|---|---|
@@ -1,25 +1,29 @@ | ||
package com.yapp.sharefood.favorite.advice; | ||
|
||
import com.yapp.sharefood.common.error.ErrorResponse; | ||
import com.yapp.sharefood.favorite.exception.FavoriteNotFoundException; | ||
import com.yapp.sharefood.favorite.exception.TooManyFavoriteException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
@Order(Ordered.HIGHEST_PRECEDENCE) | ||
public class FavoriteAdviceController { | ||
@ExceptionHandler(FavoriteNotFoundException.class) | ||
protected ResponseEntity<Object> handleFavoriteNotFoundException(final FavoriteNotFoundException exception) { | ||
protected ResponseEntity<ErrorResponse> handleFavoriteNotFoundException(final FavoriteNotFoundException exception) { | ||
log.info("FavoriteNotFoundException: {}", exception.getMessage(), exception); | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage()); | ||
return ErrorResponse.toResponseEntity(HttpStatus.NOT_FOUND, exception.getMessage()); | ||
} | ||
|
||
@ExceptionHandler(TooManyFavoriteException.class) | ||
protected ResponseEntity<Object> handleTooManyFavoriteException(final TooManyFavoriteException exception) { | ||
protected ResponseEntity<ErrorResponse> handleTooManyFavoriteException(final TooManyFavoriteException exception) { | ||
log.info("handleTooManyFavoriteException : {}", exception.getMessage(), exception); | ||
return ResponseEntity.status(HttpStatus.TOO_MANY_REQUESTS).body(exception.getMessage()); | ||
return ErrorResponse.toResponseEntity(HttpStatus.TOO_MANY_REQUESTS, exception.getMessage()); | ||
} | ||
} |
10 changes: 6 additions & 4 deletions
10
module-api/src/main/java/com/yapp/sharefood/flavor/advice/FlavorAdviceController.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 |
---|---|---|
@@ -1,21 +1,23 @@ | ||
package com.yapp.sharefood.flavor.advice; | ||
|
||
import com.yapp.sharefood.common.error.ErrorResponse; | ||
import com.yapp.sharefood.flavor.exception.FlavorNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
@RequiredArgsConstructor | ||
@Order(Ordered.HIGHEST_PRECEDENCE) | ||
public class FlavorAdviceController { | ||
|
||
@ExceptionHandler(FlavorNotFoundException.class) | ||
protected ResponseEntity<Object> handleFlavorNotFoundException(final FlavorNotFoundException exception) { | ||
protected ResponseEntity<ErrorResponse> handleFlavorNotFoundException(final FlavorNotFoundException exception) { | ||
log.info("FlavorNotFoundException: {}", exception.getMessage(), exception); | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage()); | ||
return ErrorResponse.toResponseEntity(HttpStatus.NOT_FOUND, exception.getMessage()); | ||
} | ||
} |
Oops, something went wrong.