Exception handling #82
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user