Class ResponseException

java.lang.Object
java.lang.Throwable
java.lang.Exception
org.forgerock.http.protocol.ResponseException
All Implemented Interfaces:
Serializable

public class ResponseException extends Exception
An HTTP Framework Exception that can be used by filters/handlers to simplify control-flow inside async call-backs.

As a developer, it's still useful to be able to use try-catch blocks, even if the catch block converts the ResponseException to a Promise<Response, ...>.

Note that this is a convenience class offered by the HTTP Framework, there is no requirement to use it in Filter or Handler implementations:

  • Ease control-flow inside async call-backs or in synchronous code
  • Contains a Response that may be used to forward an error message without losing detailed information about the cause of the failure
  • Contained Response may be automatically associated to this exception in order to keep track of the original failure
See Also:
  • Constructor Details

    • ResponseException

      public ResponseException(String message)
      Constructs a ResponseException using the given message.
      Parameters:
      message - Error message
    • ResponseException

      public ResponseException(Response response)
      Constructs a ResponseException using the given response. The provided Response won't be linked to this exception.
      Parameters:
      response - Response
      See Also:
    • ResponseException

      public ResponseException(String message, Throwable cause)
      Constructs a ResponseException using the given message and parent cause. This constructor also build a Response object that will be linked to this exception instance.
      Parameters:
      message - Error message
      cause - Error cause
    • ResponseException

      public ResponseException(Response response, String message, Throwable cause)
      Constructs a ResponseException using the given response, message and parent cause. The provided Response won't be linked to this exception.
      Parameters:
      response - response object
      message - Error message
      cause - Error cause
  • Method Details

    • getResponse

      public Response getResponse()
      Returns the response associated to this exception. It is intended to be used when propagating a specific Response message (constructed at the point where the original error occurred) in try-catch blocks:
           try {
               doSomeStuff(request);
             } catch (ResponseException e) {
               return Promises.newResultPromise(e.getResponse());
             }
       

      It can also be used as an informal pointer to the message that caused the exception (Client API usage)

      Returns:
      the response linked to this exception.