-
Notifications
You must be signed in to change notification settings - Fork 0
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
c00715a
commit 7defe0f
Showing
12 changed files
with
287 additions
and
6 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...ntication-server/src/main/java/dev/earlspilner/auth/rest/advice/RestControllerAdvice.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,40 @@ | ||
package dev.earlspilner.auth.rest.advice; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ProblemDetail; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
import static org.springframework.http.HttpStatus.*; | ||
|
||
/** | ||
* @author Alexander Dudkin | ||
*/ | ||
@ControllerAdvice | ||
public class RestControllerAdvice { | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<ProblemDetail> handleException(Exception e) { | ||
ProblemDetail problemDetail = createProblemDetail(INTERNAL_SERVER_ERROR, e.getMessage()); | ||
return ResponseEntity.status(INTERNAL_SERVER_ERROR).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(BadUserCredentialsException.class) | ||
public ResponseEntity<ProblemDetail> handleBadUserCredentialsException(BadUserCredentialsException e) { | ||
ProblemDetail problemDetail = createProblemDetail(BAD_REQUEST, e.getMessage()); | ||
return ResponseEntity.status(BAD_REQUEST).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(UsernameNotFoundException.class) | ||
public ResponseEntity<ProblemDetail> handleIllegalArgumentException(IllegalArgumentException e) { | ||
ProblemDetail problemDetail = createProblemDetail(NOT_FOUND, e.getMessage()); | ||
return ResponseEntity.status(NOT_FOUND).body(problemDetail); | ||
} | ||
|
||
private ProblemDetail createProblemDetail(HttpStatus status, String title) { | ||
return ProblemDetail.forStatusAndDetail(status, title); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...i-books-service/src/main/java/dev/earlspilner/books/rest/advice/RestControllerAdvice.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,51 @@ | ||
package dev.earlspilner.books.rest.advice; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ProblemDetail; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
import static org.springframework.http.HttpStatus.*; | ||
|
||
/** | ||
* @author Alexander Dudkin | ||
*/ | ||
@ControllerAdvice | ||
public class RestControllerAdvice { | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<ProblemDetail> handleException(Exception e) { | ||
ProblemDetail problemDetail = createProblemDetail(INTERNAL_SERVER_ERROR, e.getMessage()); | ||
return ResponseEntity.status(INTERNAL_SERVER_ERROR).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(UnauthorizedOperationException.class) | ||
public ResponseEntity<ProblemDetail> handleUnauthorizedOperationException(UnauthorizedOperationException e) { | ||
ProblemDetail problemDetail = createProblemDetail(HttpStatus.UNAUTHORIZED, e.getMessage()); | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(BookExistsException.class) | ||
public ResponseEntity<ProblemDetail> handleBookExistsException(BookExistsException e) { | ||
ProblemDetail problemDetail = createProblemDetail(BAD_REQUEST, e.getMessage()); | ||
return ResponseEntity.status(BAD_REQUEST).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(BookNotFoundException.class) | ||
public ResponseEntity<ProblemDetail> handleBookNotFoundException(BookNotFoundException e) { | ||
ProblemDetail problemDetail = createProblemDetail(NOT_FOUND, e.getMessage()); | ||
return ResponseEntity.status(NOT_FOUND).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(IllegalArgumentException.class) | ||
public ResponseEntity<ProblemDetail> handleIllegalArgumentException(IllegalArgumentException e) { | ||
ProblemDetail problemDetail = createProblemDetail(BAD_REQUEST, e.getMessage()); | ||
return ResponseEntity.status(BAD_REQUEST).body(problemDetail); | ||
} | ||
|
||
private ProblemDetail createProblemDetail(HttpStatus status, String title) { | ||
return ProblemDetail.forStatusAndDetail(status, title); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...rvice/src/main/java/dev/earlspilner/books/rest/advice/UnauthorizedOperationException.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,7 @@ | ||
package dev.earlspilner.books.rest.advice; | ||
|
||
public class UnauthorizedOperationException extends RuntimeException { | ||
public UnauthorizedOperationException(String message) { | ||
super(message); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...brary-service/src/main/java/dev/earlspilner/library/rest/advice/RestControllerAdvice.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,45 @@ | ||
package dev.earlspilner.library.rest.advice; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ProblemDetail; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
import static org.springframework.http.HttpStatus.*; | ||
|
||
/** | ||
* @author Alexander Dudkin | ||
*/ | ||
@ControllerAdvice | ||
public class RestControllerAdvice { | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<ProblemDetail> handleException(Exception e) { | ||
ProblemDetail problemDetail = createProblemDetail(INTERNAL_SERVER_ERROR, e.getMessage()); | ||
return ResponseEntity.status(INTERNAL_SERVER_ERROR).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(UnauthorizedOperationException.class) | ||
public ResponseEntity<ProblemDetail> handleUnauthorizedOperationException(UnauthorizedOperationException e) { | ||
ProblemDetail problemDetail = createProblemDetail(HttpStatus.UNAUTHORIZED, e.getMessage()); | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(BookRecordNotFoundException.class) | ||
public ResponseEntity<ProblemDetail> handleBookRecordNotFoundException(BookRecordNotFoundException e) { | ||
ProblemDetail problemDetail = createProblemDetail(NOT_FOUND, e.getMessage()); | ||
return ResponseEntity.status(NOT_FOUND).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(IllegalArgumentException.class) | ||
public ResponseEntity<ProblemDetail> handleIllegalArgumentException(IllegalArgumentException e) { | ||
ProblemDetail problemDetail = createProblemDetail(BAD_REQUEST, e.getMessage()); | ||
return ResponseEntity.status(BAD_REQUEST).body(problemDetail); | ||
} | ||
|
||
private ProblemDetail createProblemDetail(HttpStatus status, String title) { | ||
return ProblemDetail.forStatusAndDetail(status, title); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...ice/src/main/java/dev/earlspilner/library/rest/advice/UnauthorizedOperationException.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,7 @@ | ||
package dev.earlspilner.library.rest.advice; | ||
|
||
public class UnauthorizedOperationException extends RuntimeException { | ||
public UnauthorizedOperationException(String message) { | ||
super(message); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...pi-loan-service/src/main/java/dev/earlspilner/loans/rest/advice/RestControllerAdvice.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,45 @@ | ||
package dev.earlspilner.loans.rest.advice; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ProblemDetail; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
import static org.springframework.http.HttpStatus.*; | ||
|
||
/** | ||
* @author Alexander Dudkin | ||
*/ | ||
@ControllerAdvice | ||
public class RestControllerAdvice { | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<ProblemDetail> handleException(Exception e) { | ||
ProblemDetail problemDetail = createProblemDetail(INTERNAL_SERVER_ERROR, e.getMessage()); | ||
return ResponseEntity.status(INTERNAL_SERVER_ERROR).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(UnauthorizedOperationException.class) | ||
public ResponseEntity<ProblemDetail> handleUnauthorizedOperationException(UnauthorizedOperationException e) { | ||
ProblemDetail problemDetail = createProblemDetail(HttpStatus.UNAUTHORIZED, e.getMessage()); | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(LoanNotFoundException.class) | ||
public ResponseEntity<ProblemDetail> handleLoanNotFoundException(LoanNotFoundException e) { | ||
ProblemDetail problemDetail = createProblemDetail(NOT_FOUND, e.getMessage()); | ||
return ResponseEntity.status(NOT_FOUND).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(UnsupportedOperationException.class) | ||
public ResponseEntity<ProblemDetail> handleUnsupportedOperationException(UnsupportedOperationException e) { | ||
ProblemDetail problemDetail = createProblemDetail(UNPROCESSABLE_ENTITY, e.getMessage()); | ||
return ResponseEntity.status(UNPROCESSABLE_ENTITY).body(problemDetail); | ||
} | ||
|
||
private ProblemDetail createProblemDetail(HttpStatus status, String title) { | ||
return ProblemDetail.forStatusAndDetail(status, title); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...rvice/src/main/java/dev/earlspilner/loans/rest/advice/UnauthorizedOperationException.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,7 @@ | ||
package dev.earlspilner.loans.rest.advice; | ||
|
||
public class UnauthorizedOperationException extends RuntimeException { | ||
public UnauthorizedOperationException(String message) { | ||
super(message); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...i-users-service/src/main/java/dev/earlspilner/users/rest/advice/RestControllerAdvice.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,45 @@ | ||
package dev.earlspilner.users.rest.advice; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ProblemDetail; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
import static org.springframework.http.HttpStatus.*; | ||
|
||
/** | ||
* @author Alexander Dudkin | ||
*/ | ||
@ControllerAdvice | ||
public class RestControllerAdvice { | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<ProblemDetail> handleException(Exception e) { | ||
ProblemDetail problemDetail = createProblemDetail(INTERNAL_SERVER_ERROR, e.getMessage()); | ||
return ResponseEntity.status(INTERNAL_SERVER_ERROR).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(UnauthorizedOperationException.class) | ||
public ResponseEntity<ProblemDetail> handleUnauthorizedOperationException(UnauthorizedOperationException e) { | ||
ProblemDetail problemDetail = createProblemDetail(HttpStatus.UNAUTHORIZED, e.getMessage()); | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(UserExistsException.class) | ||
public ResponseEntity<ProblemDetail> handleUserExistsException(UserExistsException e) { | ||
ProblemDetail problemDetail = createProblemDetail(CONFLICT, e.getMessage()); | ||
return ResponseEntity.status(CONFLICT).body(problemDetail); | ||
} | ||
|
||
@ExceptionHandler(UserNotFoundException.class) | ||
public ResponseEntity<ProblemDetail> handleUserNotFoundException(UserNotFoundException e) { | ||
ProblemDetail problemDetail = createProblemDetail(NOT_FOUND, e.getMessage()); | ||
return ResponseEntity.status(NOT_FOUND).body(problemDetail); | ||
} | ||
|
||
private ProblemDetail createProblemDetail(HttpStatus status, String title) { | ||
return ProblemDetail.forStatusAndDetail(status, title); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...rvice/src/main/java/dev/earlspilner/users/rest/advice/UnauthorizedOperationException.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,7 @@ | ||
package dev.earlspilner.users.rest.advice; | ||
|
||
public class UnauthorizedOperationException extends RuntimeException { | ||
public UnauthorizedOperationException(String message) { | ||
super(message); | ||
} | ||
} |
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