Package de.odrotbohm.spring.web.model
Class MappedPayloads.MappedErrors
java.lang.Object
de.odrotbohm.spring.web.model.MappedPayloads.MappedErrors
- Direct Known Subclasses:
MappedPayloads.MappedPayload
- Enclosing interface:
- MappedPayloads
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Optional<org.springframework.http.ResponseEntity<?>>onErrors(Function<org.springframework.validation.Errors, org.springframework.http.ResponseEntity<?>> callback) org.springframework.http.ResponseEntity<?>onValidGet(Supplier<org.springframework.http.ResponseEntity<?>> response) Creates anHttpEntityif theMappedPayloads.MappedPayloadis valid, i.e.peekErrors(Consumer<org.springframework.validation.Errors> errors) Allows to peek at the currentErrorsinstance.rejectField(boolean condition, String field, String errorCode) Rejects the field with the given name with the given error code if the given condition is true.rejectField(boolean condition, String field, String errorCode, Function<org.springframework.validation.Errors, org.springframework.http.ResponseEntity<?>> errorHandler) Rejects the field with the given name with the given error code if the given condition is true.rejectField(String field, String errorCode) Rejects the field of the given name with the given error code.rejectField(String field, String errorCode, String defaultMessage) Rejects the field with the given name with the given error code and default message.org.springframework.http.ResponseEntity<?>Unconditionally creates aHttpStatus.BAD_REQUESTwith the currentErrorsas payload.<T> MappedPayloads.MappedPayload<T>with(T payload) Creates a newMappedPayloads.MappedPayloadwith the given payload and the currentErrorsinstance.
-
Field Details
-
onErrors
protected final Function<org.springframework.validation.Errors,org.springframework.http.ResponseEntity<?>> onErrors
-
-
Constructor Details
-
MappedErrors
public MappedErrors()
-
-
Method Details
-
with
Creates a newMappedPayloads.MappedPayloadwith the given payload and the currentErrorsinstance.- Type Parameters:
T-- Parameters:
payload- must not be null.- Returns:
- will never be null.
-
peekErrors
public MappedPayloads.MappedErrors peekErrors(Consumer<org.springframework.validation.Errors> errors) Allows to peek at the currentErrorsinstance.- Parameters:
errors- must not be null.- Returns:
- the current instance, never null.
-
rejectField
Rejects the field of the given name with the given error code.- Parameters:
field- must not be null or empty.errorCode- must not be null or empty.- Returns:
- the current instance, never null.
-
rejectField
Rejects the field with the given name with the given error code if the given condition is true.- Parameters:
condition- the condition under which to reject the given field.field- must not be null or empty.errorCode- must not be null or empty.- Returns:
- the current instance, never null.
-
rejectField
public MappedPayloads.MappedErrors rejectField(String field, String errorCode, String defaultMessage) Rejects the field with the given name with the given error code and default message.- Parameters:
field- must not be null or empty.errorCode- must not be null or empty.defaultMessage- must not be null or empty.- Returns:
- the current instance, never null.
-
rejectField
public MappedPayloads.MappedErrors rejectField(boolean condition, String field, String errorCode, Function<org.springframework.validation.Errors, org.springframework.http.ResponseEntity<?>> errorHandler) Rejects the field with the given name with the given error code if the given condition is true.- Parameters:
condition- the condition under which to reject the given field.field- must not be null or empty.errorCode- must not be null or empty.errorHandler- and error handler to be registered in case the condition is true.- Returns:
- the current instance, never null.
-
toBadRequest
public org.springframework.http.ResponseEntity<?> toBadRequest()Unconditionally creates aHttpStatus.BAD_REQUESTwith the currentErrorsas payload.- Returns:
- will never be null.
-
onValidGet
public org.springframework.http.ResponseEntity<?> onValidGet(Supplier<org.springframework.http.ResponseEntity<?>> response) Creates anHttpEntityif theMappedPayloads.MappedPayloadis valid, i.e. the underlyingErrorshas not accumulated any errors through previous validations.- Parameters:
response- must not be null.- Returns:
-
onErrors
public MappedPayloads.MappedErrors onErrors(Function<org.springframework.validation.Errors, org.springframework.http.ResponseEntity<?>> callback) Registers aFunctionto eventually turn anErrorsinstance into anHttpEntity. Will only be used if theErrorshave accumulated at least one error in the pipeline.- Parameters:
callback- must not be null.- Returns:
-
onErrors
public MappedPayloads.MappedErrors onErrors(Supplier<org.springframework.http.ResponseEntity<?>> callback) -
errorsOrNone
-