-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add specific exception in the number module (#8)
* feature: add specific exception in the number module * chore: upgrade spring authorization server to 0.4.0 * doc: update spring authorization server version Co-authored-by: Alexandre Touret <alexandre-touret@users.noreply.github.com>
- Loading branch information
1 parent
c890292
commit 8ec0b33
Showing
9 changed files
with
96 additions
and
34 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
41 changes: 41 additions & 0 deletions
41
rest-number/src/main/java/info/touret/bookstore/spring/number/GlobalExceptionHandler.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,41 @@ | ||
package info.touret.bookstore.spring.number; | ||
|
||
import info.touret.bookstore.spring.number.exception.ISBNExecutionException; | ||
import info.touret.bookstore.spring.number.generated.dto.APIErrorDto; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import java.util.concurrent.TimeoutException; | ||
|
||
/** | ||
* Handles all the exceptions thrown by the application | ||
*/ | ||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
/** | ||
* Indicates that the application is on maintenance | ||
*/ | ||
@ResponseStatus(HttpStatus.GATEWAY_TIMEOUT) | ||
@ExceptionHandler({ TimeoutException.class, ISBNExecutionException.class}) | ||
public APIErrorDto timeout() { | ||
APIErrorDto apiErrorDto = new APIErrorDto(); | ||
apiErrorDto.setCode(HttpStatus.GATEWAY_TIMEOUT.value()); | ||
apiErrorDto.setReason("Timeout"); | ||
return apiErrorDto; | ||
} | ||
|
||
/** | ||
* Any other exception | ||
*/ | ||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | ||
@ExceptionHandler({RuntimeException.class, Exception.class}) | ||
public APIErrorDto anyException() { | ||
APIErrorDto apiErrorDto = new APIErrorDto(); | ||
apiErrorDto.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value()); | ||
apiErrorDto.setReason("An unexpected server error occured"); | ||
return apiErrorDto; | ||
} | ||
} |
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
...r/src/main/java/info/touret/bookstore/spring/number/exception/ISBNExecutionException.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 info.touret.bookstore.spring.number.exception; | ||
|
||
public class ISBNExecutionException extends RuntimeException{ | ||
public ISBNExecutionException() { | ||
} | ||
|
||
public ISBNExecutionException(String message) { | ||
super(message); | ||
} | ||
|
||
public ISBNExecutionException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ISBNExecutionException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public ISBNExecutionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
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