diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/BaseValidatingInterceptor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/BaseValidatingInterceptor.java index e6170c7e00d..e22d7e0f6d0 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/BaseValidatingInterceptor.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/BaseValidatingInterceptor.java @@ -267,6 +267,11 @@ abstract class BaseValidatingInterceptor extends InterceptorAdapter { */ protected void postProcessResult(RequestDetails theRequestDetails, ValidationResult theValidationResult) { } + /** + * Hook for subclasses on failure (e.g. add a response header to an incoming resource upon rejection). + */ + protected void postProcessResultOnFailure(RequestDetails theRequestDetails, ValidationResult theValidationResult) { } + /** * Note: May return null */ @@ -314,6 +319,7 @@ abstract class BaseValidatingInterceptor extends InterceptorAdapter { if (myFailOnSeverity != null) { for (SingleValidationMessage next : validationResult.getMessages()) { if (next.getSeverity().ordinal() >= myFailOnSeverity) { + postProcessResultOnFailure(theRequestDetails, validationResult); fail(theRequestDetails, validationResult); return validationResult; } diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e4fa4eff160..3448d43e454 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -202,6 +202,11 @@ the JPA database, improving performance of this operation. Thanks to Joel Schneider for the pull request and analysis! + + A new post-processing hook for subclasses of BaseValidatingInterceptor is now + available. The hook exposes the request details on validation failure prior to throwing an + UnprocessableEntityException. +