Skip to content
Snippets Groups Projects
Verified Commit 96a5d50e authored by Martin Weise's avatar Martin Weise
Browse files

Fixed

parent 19cab958
No related branches found
No related tags found
2 merge requests!379Fixed the sync,!377Fixed the sync
...@@ -21,7 +21,14 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { ...@@ -21,7 +21,14 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler {
@ResponseStatus(code = HttpStatus.UNAUTHORIZED) @ResponseStatus(code = HttpStatus.UNAUTHORIZED)
@ExceptionHandler(TokenExpiredException.class) @ExceptionHandler(TokenExpiredException.class)
public ResponseEntity<ApiErrorDto> handle(TokenExpiredException e) { public ResponseEntity<ApiErrorDto> handle(TokenExpiredException e) {
return generic_handle(e.getClass(), e.getLocalizedMessage(), "error.token.expired"); final HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/problem+json");
final ApiErrorDto response = ApiErrorDto.builder()
.status(HttpStatus.UNAUTHORIZED)
.message(e.getLocalizedMessage())
.code("error.token.expired")
.build();
return new ResponseEntity<>(response, headers, response.getStatus());
} }
@Hidden @Hidden
...@@ -473,17 +480,13 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { ...@@ -473,17 +480,13 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler {
} }
private ResponseEntity<ApiErrorDto> generic_handle(Class<?> exceptionClass, String message) { private ResponseEntity<ApiErrorDto> generic_handle(Class<?> exceptionClass, String message) {
return generic_handle(exceptionClass, message, exceptionClass.getAnnotation(ResponseStatus.class).reason());
}
private ResponseEntity<ApiErrorDto> generic_handle(Class<?> exceptionClass, String message, String code) {
final HttpHeaders headers = new HttpHeaders(); final HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/problem+json"); headers.set("Content-Type", "application/problem+json");
final ResponseStatus annotation = exceptionClass.getAnnotation(ResponseStatus.class); final ResponseStatus annotation = exceptionClass.getAnnotation(ResponseStatus.class);
final ApiErrorDto response = ApiErrorDto.builder() final ApiErrorDto response = ApiErrorDto.builder()
.status(annotation.code()) .status(annotation.code())
.message(message) .message(message)
.code(code) .code(exceptionClass.getAnnotation(ResponseStatus.class).reason())
.build(); .build();
return new ResponseEntity<>(response, headers, response.getStatus()); return new ResponseEntity<>(response, headers, response.getStatus());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment