added WrongServiceTypeException

This commit is contained in:
2026-04-08 22:33:04 +02:00
parent 00bb929f22
commit ef4ee70aac
5 changed files with 17 additions and 3 deletions
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
import com.vaessl.app.dto.ConnectionRequest;
import com.vaessl.app.dto.ConnectionResponse;
import com.vaessl.app.exception.WrongServiceTypeException;
@Service
public class ConnectionService {
@@ -26,6 +27,10 @@ public class ConnectionService {
ConnectionProvider provider = providerRegistry.get(request.serviceType());
if (provider == null) {
throw new WrongServiceTypeException();
}
provider.checkCredentials(request);
ConnectionResponse response = provider.authenticate(request);
@@ -8,7 +8,7 @@ public enum ErrorMessage {
BAD_REQUEST_EMPTY_FIELDS(HttpStatus.BAD_REQUEST, "Fields must not be empty."), UNAUTHORIZED_WRONG_LOGIN(
HttpStatus.UNAUTHORIZED, "Invalid username or password."), SERVICE_UNAVAILABLE_UNREACHABLE_URL(
HttpStatus.SERVICE_UNAVAILABLE, "The target URL is unreachable."), SERVER_ERROR_GENERAL(
"The external app returned a server error: "), WRONG_SERVICE_TYPE(HttpStatus.BAD_REQUEST,
"The external app returned a server error: "), WRONG_SERVICE_TYPE(HttpStatus.NOT_FOUND,
"No such service type.");
private final HttpStatus status;
@@ -48,6 +48,11 @@ public class GlobalExceptionHandler {
SERVER_ERROR_GENERAL.getMessage() + e.getStatusText());
}
@ExceptionHandler(WrongServiceTypeException.class)
public ProblemDetail handleWrongServiceType(WrongServiceTypeException e) {
return ProblemDetail.forStatusAndDetail(WRONG_SERVICE_TYPE.getStatus(), WRONG_SERVICE_TYPE.getMessage());
}
@ExceptionHandler(EmptyCredentialsException.class)
public ProblemDetail handleEmptyCredentials(EmptyCredentialsException e) {
return ProblemDetail.forStatusAndDetail(BAD_REQUEST_EMPTY_FIELDS.getStatus(),
@@ -0,0 +1,4 @@
package com.vaessl.app.exception;
public class WrongServiceTypeException extends RuntimeException {
}