-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3dde7c
commit 66fa799
Showing
43 changed files
with
383 additions
and
320 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
19 changes: 19 additions & 0 deletions
19
adapter/src/main/java/eu/happycoders/shop/adapter/in/rest/common/ClientErrorException.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,19 @@ | ||
package eu.happycoders.shop.adapter.in.rest.common; | ||
|
||
import lombok.Getter; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
/** | ||
* An exception to be thrown in case of a client error (e.g., invalid input). | ||
* | ||
* @author Sven Woltmann | ||
*/ | ||
public class ClientErrorException extends RuntimeException { | ||
|
||
@Getter private final ResponseEntity<ErrorEntity> response; | ||
|
||
public ClientErrorException(ResponseEntity<ErrorEntity> response) { | ||
super(response.getBody().errorMessage()); | ||
this.response = response; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
adapter/src/main/java/eu/happycoders/shop/adapter/in/rest/common/ClientErrorHandler.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,19 @@ | ||
package eu.happycoders.shop.adapter.in.rest.common; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
/** | ||
* Handles {@link ClientErrorException} by returning a JSON body containing the error details. | ||
* | ||
* @author Sven Woltmann | ||
*/ | ||
@RestControllerAdvice | ||
public class ClientErrorHandler { | ||
|
||
@ExceptionHandler(ClientErrorException.class) | ||
public ResponseEntity<ErrorEntity> handleProductNotFoundException(ClientErrorException ex) { | ||
return ex.getResponse(); | ||
} | ||
} |
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.