Module rxmicro.http

Class HttpErrorException

  • All Implemented Interfaces:
    Serializable
    Direct Known Subclasses:
    InternalHttpErrorException, RedirectException, ValidationException

    public class HttpErrorException
    extends io.rxmicro.common.RxMicroException
    Base exception for all not success HTTP response statuses.

    Each reactive type of returned request handler result supports two states:

    • Successful completion signal.
    • Completion signal with an error.

    The feature of a successful completion signal consists in its uniqueness, i.e. if such a signal has occurred, it ensures successful completion of the business task. The feature of a completion signal with an error is that different types of errors may occur during the execution of the business task:

    • validation error;
    • data source connection error;
    • computational algorithm error, etc.

    It means that each request handler can return only one successful result and several results with errors.

    So the RxMicro framework introduces the error concept. An error means any unsuccessful result. For simplified error handling, the RxMicro framework recommends using HTTP status codes for each error category! In case the HTTP code status is not sufficient, the RxMicro framework recommends using an additional text description.

    For this purpose, the RxMicro framework defines a standard JSON model which is returned in case of any error:

     {
        "message": "Not Found"
     }
     

    Thus, in case of an error, the client determines the error category basing on HTTP status code analysis. For more information, the client should analyze a text message.

    For all child classes which extend the HttpErrorException class, when creating an exception instance the stack trace is not filled, as this information is redundant. (This behavior is achieved by using the RuntimeException(String, Throwable, boolean, boolean).)

    Since:
    0.1
    Author:
    nedis
    See Also:
    Serialized Form
    • Constructor Detail

      • HttpErrorException

        public HttpErrorException​(int statusCode,
                                  String message)
        Creates a HTTP error with status code and error message.

        For all child classes which extend the HttpErrorException class, when creating an exception instance the stack trace is not filled, as this information is redundant.

        (This behavior is achieved by using the RuntimeException(String, Throwable, boolean, boolean).)

        Parameters:
        statusCode - the status code
        message - the error message
        Throws:
        NullPointerException - if the error message is null
      • HttpErrorException

        public HttpErrorException​(int statusCode,
                                  String message,
                                  Object... args)
        Creates a HTTP error with status code and error message.

        For all child classes which extend the HttpErrorException class, when creating an exception instance the stack trace is not filled, as this information is redundant.

        (This behavior is achieved by using the RuntimeException(String, Throwable, boolean, boolean).)

        (FYI: This constructor uses Formats.format(String, Object...) method to format error message.)

        Parameters:
        statusCode - the status code
        message - the error message template
        args - the error message template argument
        Throws:
        NullPointerException - if the error message template is null
        IllegalArgumentException - if detected a redundant placeholder or missing argument
      • HttpErrorException

        public HttpErrorException​(int statusCode)
        Creates a HTTP error with status code only.

        For all child classes which extend the HttpErrorException class, when creating an exception instance the stack trace is not filled, as this information is redundant.

        (This behavior is achieved by using the RuntimeException(String, Throwable, boolean, boolean).)

        Parameters:
        statusCode - the status code
    • Method Detail

      • getStatusCode

        public final int getStatusCode()
      • isInformationalCode

        public final boolean isInformationalCode()
      • isSuccessCode

        public final boolean isSuccessCode()
      • isRedirectCode

        public final boolean isRedirectCode()
      • isClientErrorCode

        public final boolean isClientErrorCode()
      • isServerErrorCode

        public final boolean isServerErrorCode()