Class FinishRequestException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
io.github.grumpystuff.grumpyrest.response.FinishRequestException
All Implemented Interfaces:
ResponseValueWrapper, Serializable

public class FinishRequestException extends RuntimeException implements ResponseValueWrapper
This exception type can be thrown to immediately finish handling a request and respond with a specific response value. This value can be a normal response value, a response using the standard error format, a custom HTTP-level response such as a redirect, or whatever.

This class achieves this by bringing two things together: Being an exception for the control-flow part (stop handling the request immediately) and implementing ResponseValueWrapper to provide an arbitrary value as if it were returned from a handler.

The latter causes the framework to select an appropriate ResponseFactory for that wrapped value. This uses the normal mechanism to handle response values, but will usually be one of two cases: Either the response value is JSON-able (normal response, as well as standard error response) or is a Response itself (redirect, request for HTTP authentication, or similar).

See Also:
  • Constructor Details

    • FinishRequestException

      public FinishRequestException(Object responseValue)
      Constructor.
      Parameters:
      responseValue - the response value to respond
  • Method Details

    • getWrappedResponseValue

      public Object getWrappedResponseValue()
      Description copied from interface: ResponseValueWrapper
      Getter method for the response value wrapped by this wrapper.

      If the wrapped value is itself an instance of this interface, then the implementation does not have to unwrap that wrapper too -- the caller of this method is expected to unwrap as often as possible.

      Specified by:
      getWrappedResponseValue in interface ResponseValueWrapper
      Returns:
      the wrapped response value