Class HttpError

    • Constructor Detail

      • HttpError

        public HttpError​(int statusCode,
                         String statusText)
        Creates a new HttpError instance with the specified status code and status text. It is preferable and easier to use the specific class for the standard status code that you want send, so only use this constructor for non-standard custom response status codes
        Parameters:
        statusCode - HTTP status code
        statusText - HTTP status message
      • HttpError

        public HttpError​(int statusCode,
                         String statusText,
                         String message)
        Creates a new HttpError instance with the specified status code and status text and a custom error message to be serialized out in default JSON serialization. It is preferable and easier to use the specific class for the standard status code that you want send, so only use this constructor for non-standard custom response status codes
        Parameters:
        statusCode - HTTP status code
        statusText - HTTP status message
        message - The error message to show in the body of the response
      • HttpError

        public HttpError​(int statusCode,
                         String statusText,
                         Throwable throwable)
        Creates a new HttpError instance with the specified status code and status text and a causing exception. The resulting exception will serialize the cause's message as the error message in default JSON serialization. It is preferable and easier to use the specific class for the standard status code that you want send, so only use this constructor for non-standard custom response status codes
        Parameters:
        statusCode - HTTP status code
        statusText - HTTP status message
        throwable - The exception causing this status to be sent
      • HttpError

        public HttpError​(int statusCode,
                         String statusText,
                         String message,
                         Throwable throwable)
        Creates a new HttpError instance with the specified status code and status text and a causing exception. The resulting exception will serialize the provided custom message as the error message in default JSON serialization, instead of the cause's message. It is preferable and easier to use the specific class for the standard status code that you want send, so only use this constructor for non-standard custom response status codes
        Parameters:
        statusCode - HTTP status code
        statusText - HTTP status message
        message - The error message to show in the body of the response
        throwable - The exception causing this status to be sent
    • Method Detail

      • getStatusCode

        public int getStatusCode()
        Retrieve this instance's numeric HTTP status code
        Returns:
        HTTP status code
      • getStatusText

        public String getStatusText()
        Retrieve this instance's HTTP status message
        Returns:
        HTTP status message
      • setStatusText

        public HttpError setStatusText​(String reasonText)
        Update the current instance's status message with a non-default HTTP status message. The use of this method is not recommended and is offered only for supporting Vert.x HttpServerResponse.setStatusMessage(String) API.
        Parameters:
        reasonText - The non-standard HTTP status message to use
        Returns:
        the same instance for use as a fluent API
      • isOK

        public boolean isOK()
        Check whether this instance represents a 2xx class HTTP response
        Returns:
        whether the HTTP status code is between 200-299 (inclusive)
      • isRedirect

        public boolean isRedirect()
        Check whether this instance represents a 3xx class HTTP response
        Returns:
        whether the HTTP status code is between 300-399 (inclusive)
      • isClientError

        public boolean isClientError()
        Check whether this instance represents a 4xx class HTTP response
        Returns:
        whether the HTTP status code is between 400-499 (inclusive)
      • isServerError

        public boolean isServerError()
        Check whether this instance represents a 5xx class HTTP response
        Returns:
        whether the HTTP status code is between 500-599 (inclusive)
      • isError

        public boolean isError()
        Check whether this instance represents a "error class" HTTP response
        Returns:
        whether the HTTP status code is between 400-599 (inclusive)
      • addHeader

        public HttpError addHeader​(String header,
                                   String value)
        Add a header line to be written to the response's header by Irked when this status is used to send a response.
        Parameters:
        header - header name
        value - header value
        Returns:
        the same instance for use as a fluent API
      • getHeaders

        public io.vertx.core.MultiMap getHeaders()
        Retrieve a reference to the current set of additional headers.
        Returns:
        the current set of additional headers
      • unwrap

        public static Throwable unwrap​(Throwable t)
        Unwrap RuntimeException wrappers around a logical exception (hopefully an instance of HttpError)
        Parameters:
        t - Throwable to unwrap
        Returns:
        the first non RuntimeException found
      • toHttpError

        public static HttpError toHttpError​(Throwable t)
        Helper method for OnFail handlers to locate a wrapped HttpError or create an InternalServerError from an unexpected exception (whether it is wrapped or not)
        Parameters:
        t - Throwable to be analyzed
        Returns:
        the wrapped HttpError instance or a new InternalServerError wrapping the real exception
      • toHttpError

        public static HttpError toHttpError​(io.vertx.ext.web.RoutingContext ctx)
        Helper method for OnFail handlers to create an appropriate HTTP error class for a failed RoutingContext, by reading the failed status code or failure exception. If RoutingContext.failure() returns a (possibly wrapped) HttpError then that what will be returned, otherwise either an InternalServerError will be returned (for an exception failure) or an appropriate default HTTP status instance according to the failed status code. Note that if the RoutingContext.failed() == false, then an OK HTTP status class instance will be returned.
        Parameters:
        ctx - failed RoutingContext to investigate
        Returns:
        an HttpError instance representing the status of the RoutingContext