Class MappedPayloads.MappedErrors

java.lang.Object
de.odrotbohm.spring.web.model.MappedPayloads.MappedErrors
Direct Known Subclasses:
MappedPayloads.MappedPayload
Enclosing interface:
MappedPayloads

public static class MappedPayloads.MappedErrors extends Object
  • Field Details

    • onErrors

      protected final Function<org.springframework.validation.Errors,org.springframework.http.ResponseEntity<?>> onErrors
  • Constructor Details

    • MappedErrors

      public MappedErrors()
  • Method Details

    • with

      public <T> MappedPayloads.MappedPayload<T> with(T payload)
      Creates a new MappedPayloads.MappedPayload with the given payload and the current Errors instance.
      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 current Errors instance.
      Parameters:
      errors - must not be null.
      Returns:
      the current instance, never null.
    • rejectField

      public MappedPayloads.MappedErrors rejectField(String field, String errorCode)
      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

      public MappedPayloads.MappedErrors 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.
      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 a HttpStatus.BAD_REQUEST with the current Errors as payload.
      Returns:
      will never be null.
    • onValidGet

      public org.springframework.http.ResponseEntity<?> onValidGet(Supplier<org.springframework.http.ResponseEntity<?>> response)
      Creates an HttpEntity if the MappedPayloads.MappedPayload is valid, i.e. the underlying Errors has 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 a Function to eventually turn an Errors instance into an HttpEntity. Will only be used if the Errors have 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

      protected Optional<org.springframework.http.ResponseEntity<?>> errorsOrNone()