Exception handling #82

Merged
stne3960 merged 6 commits from feature/exception-handling into main 2026-02-02 11:18:37 +01:00
Showing only changes of commit 09931c5170 - Show all commits

View File

@ -0,0 +1,47 @@
package se.su.dsv.studentportalen.bff.exception;
import org.springframework.http.HttpStatus;
import java.util.List;
import java.util.Map;
/**
* Exception for validation errors, including field-level violations.
* Used for both BFF validation failures and mapped Daisy validation errors.
*/
public class ValidationException extends StudentportalenException {
private final Map<String, List<String>> violations;
public ValidationException(String message) {
this(message, Map.of());
}
public ValidationException(String message, Map<String, List<String>> violations) {
super(message);
this.violations = violations != null ? Map.copyOf(violations) : Map.of();
}
@Override
public String getType() {
return "studentportalen:validation-error";
}
@Override
public String getTitle() {
return "Validation failed";
}
@Override
public HttpStatus getStatus() {
return HttpStatus.BAD_REQUEST;
}
/**
* Field-level validation errors.
* Keys are field names, values are lists of error messages.
*/
public Map<String, List<String>> getViolations() {
return violations;
}
}