-
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.
Logging api requests with invalid tokens
Fixed request with invalid token with internal server error
- Loading branch information
1 parent
870ceec
commit 4e17a02
Showing
5 changed files
with
67 additions
and
11 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
32 changes: 32 additions & 0 deletions
32
src/main/java/de/webalf/slotbot/exception/OtherResponseEntityExceptionHandler.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,32 @@ | ||
package de.webalf.slotbot.exception; | ||
|
||
import org.springframework.core.annotation.Order; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import static de.webalf.slotbot.exception.RestResponseEntityExceptionHandler.determineHttpStatus; | ||
|
||
/** | ||
* Handles exceptions matched by {@link RestControllerAdvice}. | ||
* <p> | ||
* This translates exceptions to human-readable and valuable error messages for the caller. | ||
* | ||
* @author Alf | ||
* @since 05.10.2021 | ||
*/ | ||
@RestControllerAdvice | ||
@Order(3) | ||
public class OtherResponseEntityExceptionHandler { | ||
@ExceptionHandler(ForbiddenException.class) | ||
protected ResponseEntity<?> handleConflict(RuntimeException ex, HttpServletRequest request) { | ||
return new ResponseEntity<>( | ||
ExceptionResponse.builder() | ||
.errorMessage(ex.getMessage()) | ||
.requestedURI(request.getRequestURI()) | ||
.build(), | ||
determineHttpStatus(ex)); | ||
} | ||
} |
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