Class ServiceException

All Implemented Interfaces:
Serializable, ErrorCodeAware, HttpStatusAware

public class ServiceException extends RuntimeException implements ErrorCodeAware, HttpStatusAware
General service exception with http status code and error code.
Author:
Christian Bremer
See Also:
  • Field Details

    • ERROR_CODE_ALREADY_EXISTS

      public static final String ERROR_CODE_ALREADY_EXISTS
      Default error code for an 'already exists exception'.
      See Also:
  • Constructor Details

    • ServiceException

      protected ServiceException()
      Instantiates a new service exception.
    • ServiceException

      protected ServiceException(int httpStatus, String errorCode)
      Instantiates a new service exception.
      Parameters:
      httpStatus - the http status
      errorCode - the error code
    • ServiceException

      protected ServiceException(int httpStatus, String errorCode, String reason)
      Instantiates a new service exception.
      Parameters:
      httpStatus - the http status
      errorCode - the error code
      reason - the reason
    • ServiceException

      protected ServiceException(int httpStatus, String errorCode, Throwable cause)
      Instantiates a new service exception.
      Parameters:
      httpStatus - the http status
      errorCode - the error code
      cause - the cause
    • ServiceException

      protected ServiceException(int httpStatus, String errorCode, String reason, Throwable cause)
      Instantiates a new service exception.
      Parameters:
      httpStatus - the http status
      errorCode - the error code
      reason - the reason
      cause - the cause
  • Method Details

    • status

      public int status()
      Get the http status.
      Specified by:
      status in interface HttpStatusAware
      Returns:
      the http status
    • internalServerError

      public static ServiceException internalServerError()
      Internal server error service exception.
      Returns:
      the service exception
    • internalServerError

      public static ServiceException internalServerError(String reason)
      Internal server error service exception.
      Parameters:
      reason - the reason
      Returns:
      the service exception
    • internalServerError

      public static ServiceException internalServerError(String reason, Throwable cause)
      Internal server error service exception.
      Parameters:
      reason - the reason
      cause - the cause
      Returns:
      the service exception
    • internalServerError

      public static ServiceException internalServerError(String reason, String errorCode)
      Internal server error service exception.
      Parameters:
      reason - the reason
      errorCode - the error code
      Returns:
      the service exception
    • internalServerError

      public static ServiceException internalServerError(String reason, String errorCode, Throwable cause)
      Internal server error service exception.
      Parameters:
      reason - the reason
      errorCode - the error code
      cause - the cause
      Returns:
      the service exception
    • badRequest

      public static ServiceException badRequest()
      Bad request service exception.
      Returns:
      the service exception
    • badRequest

      public static ServiceException badRequest(String reason)
      Bad request service exception.
      Parameters:
      reason - the reason
      Returns:
      the service exception
    • badRequest

      public static ServiceException badRequest(String reason, Throwable cause)
      Bad request service exception.
      Parameters:
      reason - the reason
      cause - the cause
      Returns:
      the service exception
    • badRequest

      public static ServiceException badRequest(String reason, String errorCode)
      Bad request service exception.
      Parameters:
      reason - the reason
      errorCode - the error code
      Returns:
      the service exception
    • badRequest

      public static ServiceException badRequest(String reason, String errorCode, Throwable cause)
      Bad request service exception.
      Parameters:
      reason - the reason
      errorCode - the error code
      cause - the cause
      Returns:
      the service exception
    • notFound

      public static ServiceException notFound()
      Not found service exception.
      Returns:
      the service exception
    • notFound

      public static ServiceException notFound(Object entityName)
      Not found service exception.
      Parameters:
      entityName - the entity name
      Returns:
      the service exception
    • notFound

      public static ServiceException notFound(String entityType, Object entityName)
      Not found service exception.
      Parameters:
      entityType - the entity type
      entityName - the entity name
      Returns:
      the service exception
    • notFoundWithErrorCode

      public static ServiceException notFoundWithErrorCode(Object entityName, String errorCode)
      Not found with error code service exception.
      Parameters:
      entityName - the entity name
      errorCode - the error code
      Returns:
      the service exception
    • notFoundWithErrorCode

      public static ServiceException notFoundWithErrorCode(String entityType, Object entityName, String errorCode)
      Not found with error code service exception.
      Parameters:
      entityType - the entity type
      entityName - the entity name
      errorCode - the error code
      Returns:
      the service exception
    • alreadyExists

      public static ServiceException alreadyExists()
      Already exists service exception.
      Returns:
      the service exception
    • alreadyExists

      public static ServiceException alreadyExists(Object entityName)
      Already exists service exception.
      Parameters:
      entityName - the entity name
      Returns:
      the service exception
    • alreadyExists

      public static ServiceException alreadyExists(String entityType, Object entityName)
      Already exists service exception.
      Parameters:
      entityType - the entity type
      entityName - the entity name
      Returns:
      the service exception
    • alreadyExistsWithErrorCode

      public static ServiceException alreadyExistsWithErrorCode(Object entityName, String errorCode)
      Already exists with error code service exception.
      Parameters:
      entityName - the entity name
      errorCode - the error code
      Returns:
      the service exception
    • alreadyExistsWithErrorCode

      public static ServiceException alreadyExistsWithErrorCode(String entityType, Object entityName, String errorCode)
      Already exists with error code service exception.
      Parameters:
      entityType - the entity type
      entityName - the entity name
      errorCode - the error code
      Returns:
      the service exception
    • forbidden

      public static ServiceException forbidden()
      Forbidden service exception.
      Returns:
      the service exception
    • forbidden

      public static ServiceException forbidden(Object entityName)
      Forbidden service exception.
      Parameters:
      entityName - the entity name
      Returns:
      the service exception
    • forbidden

      public static ServiceException forbidden(String entityType, Object entityName)
      Forbidden service exception.
      Parameters:
      entityType - the entity type
      entityName - the entity name
      Returns:
      the service exception
    • forbiddenWithErrorCode

      public static ServiceException forbiddenWithErrorCode(String errorCode)
      Forbidden with error code service exception.
      Parameters:
      errorCode - the error code
      Returns:
      the service exception
    • forbiddenWithErrorCode

      public static ServiceException forbiddenWithErrorCode(Object entityName, String errorCode)
      Forbidden with error code service exception.
      Parameters:
      entityName - the entity name
      errorCode - the error code
      Returns:
      the service exception
    • forbiddenWithErrorCode

      public static ServiceException forbiddenWithErrorCode(String entityType, Object entityName, String errorCode)
      Forbidden with error code service exception.
      Parameters:
      entityType - the entity type
      entityName - the entity name
      errorCode - the error code
      Returns:
      the service exception
    • builder

      public static ServiceExceptionBuilder<? extends ServiceException> builder()
      Creates new exception builder.
      Returns:
      the builder