Package io.inversion
Class ApiException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
io.inversion.ApiException
- All Implemented Interfaces:
Status,Serializable
- See Also:
- Serialized Form
-
Field Summary
FieldsFields inherited from interface io.inversion.Status
SC_200_OK, SC_201_CREATED, SC_204_NO_CONTENT, SC_308_PERMANENT_REDIRECT, SC_400_BAD_REQUEST, SC_401_UNAUTHORIZED, SC_403_FORBIDDEN, SC_404_NOT_FOUND, SC_429_TOO_MANY_REQUESTS, SC_500_INTERNAL_SERVER_ERROR, SC_501_NOT_IMPLEMENTED -
Constructor Summary
ConstructorsConstructorDescriptionApiException(String httpStatus)ApiException(String messageFormat, Object... args)ApiException(String httpStatus, Throwable cause, String messageFormat, Object... args)ApiException(Throwable cause) -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetMessage(String httpStatus, Throwable cause, String messageFormat, Object... args)Constructs a useful error message.booleanhasStatus(int... statusCodes)static ApiExceptionstatic ApiExceptionnew400BadRequest(String messageFormat, Object... messages)static ApiExceptionnew400BadRequest(Throwable cause)static ApiExceptionnew400BadRequest(Throwable cause, String messageFormat, Object... messages)static ApiExceptionstatic ApiExceptionnew401Unauthroized(String messageFormat, Object... messages)static ApiExceptionnew401Unauthroized(Throwable cause)static ApiExceptionnew401Unauthroized(Throwable cause, String messageFormat, Object... messages)static ApiExceptionstatic ApiExceptionnew403Forbidden(String messageFormat, Object... messages)static ApiExceptionnew403Forbidden(Throwable cause)static ApiExceptionnew403Forbidden(Throwable cause, String messageFormat, Object... messages)static ApiExceptionstatic ApiExceptionnew404NotFound(String messageFormat, Object... messages)static ApiExceptionnew404NotFound(Throwable cause)static ApiExceptionnew404NotFound(Throwable cause, String messageFormat, Object... messages)static ApiExceptionstatic ApiExceptionnew429TooManyRequests(String messageFormat, Object... messages)static ApiExceptionnew429TooManyRequests(Throwable cause)static ApiExceptionnew429TooManyRequests(Throwable cause, String messageFormat, Object... messages)static ApiExceptionstatic ApiExceptionnew500InternalServerError(String messageFormat, Object... args)static ApiExceptionnew500InternalServerError(Throwable cause)static ApiExceptionnew500InternalServerError(Throwable cause, String messageFormat, Object... args)static ApiExceptionstatic ApiExceptionnew501NotImplemented(String messageFormat, Object... args)static ApiExceptionnew501NotImplemented(Throwable cause)static ApiExceptionnew501NotImplemented(Throwable cause, String messageFormat, Object... args)static voidThrows a 500 INTERNAL SERVER ERROR ApiException with the given messagestatic voidstatic voidRethrowscauseas a 500 INTERNAL SERVER ERROR ApiExceptionwithStatus(String status)Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
status
-
-
Constructor Details
-
ApiException
- Throws:
ApiException
-
ApiException
- Throws:
ApiException
-
ApiException
- Throws:
ApiException
-
ApiException
- Throws:
ApiException
-
ApiException
public ApiException(String httpStatus, Throwable cause, String messageFormat, Object... args) throws ApiException- Throws:
ApiException
-
-
Method Details
-
getMessage
public static String getMessage(String httpStatus, Throwable cause, String messageFormat, Object... args)Constructs a useful error message.All arguments are optional but if everything is null you will get an empty string.
- Parameters:
httpStatus- the HTTP stats codde of the errorcause- the cause of the errormessageFormat- the caller supplied error message with variable placeholdersargs- variables to insert intomessageFormat- Returns:
- a hopefully user friendly error message
- See Also:
Utils.format(String, Object...)
-
throwEx
Rethrowscauseas a 500 INTERNAL SERVER ERROR ApiException- Parameters:
cause- the cause of the error- Throws:
ApiException- always
-
throwEx
Throws a 500 INTERNAL SERVER ERROR ApiException with the given message- Parameters:
messageFormat- the error message potentially with variablesargs- values substituted intomessageFormat- Throws:
ApiException- always
-
throwEx
public static void throwEx(String status, Throwable cause, String messageFormat, Object... args) throws ApiException- Throws:
ApiException
-
new400BadRequest
- Throws:
ApiException
-
new400BadRequest
- Throws:
ApiException
-
new400BadRequest
public static ApiException new400BadRequest(String messageFormat, Object... messages) throws ApiException- Throws:
ApiException
-
new400BadRequest
public static ApiException new400BadRequest(Throwable cause, String messageFormat, Object... messages) throws ApiException- Throws:
ApiException
-
new401Unauthroized
- Throws:
ApiException
-
new401Unauthroized
- Throws:
ApiException
-
new401Unauthroized
public static ApiException new401Unauthroized(String messageFormat, Object... messages) throws ApiException- Throws:
ApiException
-
new401Unauthroized
public static ApiException new401Unauthroized(Throwable cause, String messageFormat, Object... messages) throws ApiException- Throws:
ApiException
-
new403Forbidden
- Throws:
ApiException
-
new403Forbidden
- Throws:
ApiException
-
new403Forbidden
public static ApiException new403Forbidden(String messageFormat, Object... messages) throws ApiException- Throws:
ApiException
-
new403Forbidden
public static ApiException new403Forbidden(Throwable cause, String messageFormat, Object... messages) throws ApiException- Throws:
ApiException
-
new404NotFound
- Throws:
ApiException
-
new404NotFound
- Throws:
ApiException
-
new404NotFound
public static ApiException new404NotFound(String messageFormat, Object... messages) throws ApiException- Throws:
ApiException
-
new404NotFound
public static ApiException new404NotFound(Throwable cause, String messageFormat, Object... messages) throws ApiException- Throws:
ApiException
-
new429TooManyRequests
- Throws:
ApiException
-
new429TooManyRequests
- Throws:
ApiException
-
new429TooManyRequests
public static ApiException new429TooManyRequests(String messageFormat, Object... messages) throws ApiException- Throws:
ApiException
-
new429TooManyRequests
public static ApiException new429TooManyRequests(Throwable cause, String messageFormat, Object... messages) throws ApiException- Throws:
ApiException
-
new500InternalServerError
- Throws:
ApiException
-
new500InternalServerError
- Throws:
ApiException
-
new500InternalServerError
public static ApiException new500InternalServerError(String messageFormat, Object... args) throws ApiException- Throws:
ApiException
-
new500InternalServerError
public static ApiException new500InternalServerError(Throwable cause, String messageFormat, Object... args) throws ApiException- Throws:
ApiException
-
new501NotImplemented
- Throws:
ApiException
-
new501NotImplemented
- Throws:
ApiException
-
new501NotImplemented
public static ApiException new501NotImplemented(String messageFormat, Object... args) throws ApiException- Throws:
ApiException
-
new501NotImplemented
public static ApiException new501NotImplemented(Throwable cause, String messageFormat, Object... args) throws ApiException- Throws:
ApiException
-
getStatus
-
withStatus
-
hasStatus
public boolean hasStatus(int... statusCodes)
-