Package io.inversion

Class ApiException

  • All Implemented Interfaces:
    Status, java.io.Serializable

    public class ApiException
    extends java.lang.RuntimeException
    implements Status
    See Also:
    Serialized Form
    • Field Detail

      • status

        protected java.lang.String status
    • Constructor Detail

      • ApiException

        public ApiException​(java.lang.String messageFormat,
                            java.lang.Object... args)
                     throws ApiException
        Throws:
        ApiException
      • ApiException

        public ApiException​(java.lang.Throwable cause,
                            java.lang.String httpStatus,
                            java.lang.String messageFormat,
                            java.lang.Object... args)
                     throws ApiException
        Throws:
        ApiException
    • Method Detail

      • getStatus

        public java.lang.String getStatus()
      • withStatus

        public ApiException withStatus​(java.lang.String status)
      • hasStatus

        public boolean hasStatus​(int... statusCodes)
      • getStatusCode

        public int getStatusCode()
      • getMessage

        public static java.lang.String getMessage​(java.lang.Throwable cause,
                                                  java.lang.String httpStatus,
                                                  java.lang.String messageFormat,
                                                  java.lang.Object... args)
        Constructs a useful error message.

        All arguments are optional but if everything is null you will get an empty string.

        Parameters:
        cause - the cause of the error
        httpStatus - the HTTP stats codde of the error
        messageFormat - the caller supplied error message with variable placeholders
        args - variables to insert into messageFormat
        Returns:
        a hopefully user friendly error message
        See Also:
        Utils.format(String, Object...)
      • throwEx

        public static void throwEx​(java.lang.Throwable cause)
                            throws ApiException
        Rethrows cause as a "500 Internal Server Error" ApiException
        Parameters:
        cause - the cause of the error
        Throws:
        ApiException - always
      • throwEx

        public static void throwEx​(java.lang.String messageFormat,
                                   java.lang.Object... args)
                            throws ApiException
        Throws a "500 Internal Server Error" ApiException with the given message
        Parameters:
        messageFormat - the error message potentially with variables
        args - values substituted into messageFormat
        Throws:
        ApiException - always
      • throwEx

        public static void throwEx​(java.lang.Throwable cause,
                                   java.lang.String status,
                                   java.lang.String messageFormat,
                                   java.lang.Object... args)
                            throws ApiException
        Throws:
        ApiException
      • new400BadRequest

        public static ApiException new400BadRequest​(java.lang.Throwable cause,
                                                    java.lang.String messageFormat,
                                                    java.lang.Object... args)
                                             throws ApiException
        Throws:
        ApiException
      • new401Unauthroized

        public static ApiException new401Unauthroized​(java.lang.Throwable cause,
                                                      java.lang.String messageFormat,
                                                      java.lang.Object... args)
                                               throws ApiException
        Throws:
        ApiException
      • new403Forbidden

        public static ApiException new403Forbidden​(java.lang.Throwable cause,
                                                   java.lang.String messageFormat,
                                                   java.lang.Object... args)
                                            throws ApiException
        Throws:
        ApiException
      • new404NotFound

        public static ApiException new404NotFound​(java.lang.Throwable cause,
                                                  java.lang.String messageFormat,
                                                  java.lang.Object... args)
                                           throws ApiException
        Throws:
        ApiException
      • new429TooManyRequests

        public static ApiException new429TooManyRequests​(java.lang.Throwable cause,
                                                         java.lang.String messageFormat,
                                                         java.lang.Object... args)
                                                  throws ApiException
        Throws:
        ApiException
      • new500InternalServerError

        public static ApiException new500InternalServerError​(java.lang.String messageFormat,
                                                             java.lang.Object... args)
                                                      throws ApiException
        Throws:
        ApiException
      • new500InternalServerError

        public static ApiException new500InternalServerError​(java.lang.Throwable cause,
                                                             java.lang.String messageFormat,
                                                             java.lang.Object... args)
                                                      throws ApiException
        Throws:
        ApiException
      • new501NotImplemented

        public static ApiException new501NotImplemented​(java.lang.Throwable cause,
                                                        java.lang.String messageFormat,
                                                        java.lang.Object... args)
                                                 throws ApiException
        Throws:
        ApiException