Package io.inversion
Class ApiException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- io.inversion.ApiException
-
- All Implemented Interfaces:
Status,java.io.Serializable
public class ApiException extends java.lang.RuntimeException implements Status
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Stringstatus-
Fields inherited from interface io.inversion.Status
SC_200_OK, SC_201_CREATED, SC_202_ACCEPTED, SC_204_NO_CONTENT, SC_307_TEMPORARY_REDIRECT, SC_308_PERMANENT_REDIRECT, SC_400_BAD_REQUEST, SC_401_UNAUTHORIZED, SC_403_FORBIDDEN, SC_404_NOT_FOUND, SC_409_CONFLICT, SC_429_TOO_MANY_REQUESTS, SC_500_INTERNAL_SERVER_ERROR, SC_501_NOT_IMPLEMENTED, SC_507_INSUFFICIENT_STORAGE, SC_599_NETWORK_CONNECT_TIMEPUT_ERROR
-
-
Constructor Summary
Constructors Constructor Description ApiException()ApiException(java.lang.String messageFormat, java.lang.Object... args)ApiException(java.lang.Throwable cause)ApiException(java.lang.Throwable cause, java.lang.String httpStatus, java.lang.String messageFormat, java.lang.Object... args)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgetMessage(java.lang.Throwable cause, java.lang.String httpStatus, java.lang.String messageFormat, java.lang.Object... args)Constructs a useful error message.java.lang.StringgetStatus()intgetStatusCode()booleanhasStatus(int... statusCodes)static ApiExceptionnew400BadRequest()static ApiExceptionnew400BadRequest(java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew400BadRequest(java.lang.Throwable cause)static ApiExceptionnew400BadRequest(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew401Unauthroized()static ApiExceptionnew401Unauthroized(java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew401Unauthroized(java.lang.Throwable cause)static ApiExceptionnew401Unauthroized(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew403Forbidden()static ApiExceptionnew403Forbidden(java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew403Forbidden(java.lang.Throwable cause)static ApiExceptionnew403Forbidden(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew404NotFound()static ApiExceptionnew404NotFound(java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew404NotFound(java.lang.Throwable cause)static ApiExceptionnew404NotFound(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew429TooManyRequests()static ApiExceptionnew429TooManyRequests(java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew429TooManyRequests(java.lang.Throwable cause)static ApiExceptionnew429TooManyRequests(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew500InternalServerError()static ApiExceptionnew500InternalServerError(java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew500InternalServerError(java.lang.Throwable cause)static ApiExceptionnew500InternalServerError(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew501NotImplemented()static ApiExceptionnew501NotImplemented(java.lang.String messageFormat, java.lang.Object... args)static ApiExceptionnew501NotImplemented(java.lang.Throwable cause)static ApiExceptionnew501NotImplemented(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... args)static voidthrowEx(java.lang.String messageFormat, java.lang.Object... args)Throws a "500 Internal Server Error" ApiException with the given messagestatic voidthrowEx(java.lang.Throwable cause)Rethrowscauseas a "500 Internal Server Error" ApiExceptionstatic voidthrowEx(java.lang.Throwable cause, java.lang.String status, java.lang.String messageFormat, java.lang.Object... args)ApiExceptionwithStatus(java.lang.String status)
-
-
-
Constructor Detail
-
ApiException
public ApiException() throws ApiException- Throws:
ApiException
-
ApiException
public ApiException(java.lang.Throwable cause) throws ApiException- Throws:
ApiException
-
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 errorhttpStatus- the HTTP stats codde 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
public static void throwEx(java.lang.Throwable cause) throws ApiExceptionRethrowscauseas 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 ApiExceptionThrows 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(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() throws ApiException
- Throws:
ApiException
-
new400BadRequest
public static ApiException new400BadRequest(java.lang.Throwable cause) throws ApiException
- Throws:
ApiException
-
new400BadRequest
public static ApiException new400BadRequest(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() throws ApiException
- Throws:
ApiException
-
new401Unauthroized
public static ApiException new401Unauthroized(java.lang.Throwable cause) throws ApiException
- Throws:
ApiException
-
new401Unauthroized
public static ApiException new401Unauthroized(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() throws ApiException
- Throws:
ApiException
-
new403Forbidden
public static ApiException new403Forbidden(java.lang.Throwable cause) throws ApiException
- Throws:
ApiException
-
new403Forbidden
public static ApiException new403Forbidden(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() throws ApiException
- Throws:
ApiException
-
new404NotFound
public static ApiException new404NotFound(java.lang.Throwable cause) throws ApiException
- Throws:
ApiException
-
new404NotFound
public static ApiException new404NotFound(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() throws ApiException
- Throws:
ApiException
-
new429TooManyRequests
public static ApiException new429TooManyRequests(java.lang.Throwable cause) throws ApiException
- Throws:
ApiException
-
new429TooManyRequests
public static ApiException new429TooManyRequests(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() throws ApiException
- Throws:
ApiException
-
new500InternalServerError
public static ApiException new500InternalServerError(java.lang.Throwable cause) 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() throws ApiException
- Throws:
ApiException
-
new501NotImplemented
public static ApiException new501NotImplemented(java.lang.Throwable cause) throws ApiException
- Throws:
ApiException
-
new501NotImplemented
public static ApiException new501NotImplemented(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
-
-