bug: fixed changed Homebox endpoint and added better exception handling.

This commit is contained in:
2026-06-23 19:08:35 +02:00
parent 5776676eeb
commit f0d536d8f4
7 changed files with 36 additions and 14 deletions
@@ -1,5 +1,7 @@
package com.vaessl.app.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ProblemDetail;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
@@ -16,6 +18,8 @@ import java.util.stream.Collectors;
@RestControllerAdvice
public class GlobalExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(MethodArgumentNotValidException.class)
public ProblemDetail handleEmptyCredentialInput(MethodArgumentNotValidException e) {
@@ -33,6 +37,15 @@ public class GlobalExceptionHandler {
UNAUTHORIZED_WRONG_LOGIN.getMessage());
}
// Catches any other 4xx from a remote API (e.g. 404 caused by a changed endpoint).
// Must come after the Unauthorized handler so Spring matches 401 there first.
@ExceptionHandler(HttpClientErrorException.class)
public ProblemDetail handleRemoteClientError(HttpClientErrorException e) {
log.error("Remote API returned {}: {}", e.getStatusCode(), e.getResponseBodyAsString());
return ProblemDetail.forStatusAndDetail(REMOTE_API_CLIENT_ERROR.getStatus(),
REMOTE_API_CLIENT_ERROR.getMessage() + e.getStatusCode());
}
@ExceptionHandler(ResourceAccessException.class)
public ProblemDetail handleNoConnection(ResourceAccessException e) {
@@ -42,7 +55,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(HttpServerErrorException.class)
public ProblemDetail handleTimeoutOrNotFound(HttpServerErrorException e) {
log.error("Remote API server error {}: {}", e.getStatusCode(), e.getResponseBodyAsString());
return ProblemDetail.forStatusAndDetail(e.getStatusCode(),
SERVER_ERROR_GENERAL.getMessage() + e.getStatusText());
}
@@ -61,12 +74,14 @@ public class GlobalExceptionHandler {
@ExceptionHandler(ConnectionNotFoundException.class)
public ProblemDetail handleConnectionNotFound(ConnectionNotFoundException e) {
return ProblemDetail.forStatusAndDetail(CONNECTION_NOT_FOUND.getStatus(), CONNECTION_NOT_FOUND.getMessage());
return ProblemDetail.forStatusAndDetail(CONNECTION_NOT_FOUND.getStatus(),
CONNECTION_NOT_FOUND.getMessage());
}
@ExceptionHandler(RemoteApiException.class)
public ProblemDetail handleRemoteApiException(RemoteApiException e) {
log.error("Remote API empty body: {}{}", e.getAppUrl(), e.getPath());
return ProblemDetail.forStatusAndDetail(REMOTE_API_EMPTY_RESPONSE.getStatus(),
REMOTE_API_EMPTY_RESPONSE.getMessage() + e.getAppUrl());
REMOTE_API_EMPTY_RESPONSE.getMessage() + e.getAppUrl() + e.getPath());
}
}