Class SmartServiceException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
RetryableSmartServiceException

public class SmartServiceException extends AppianException
An exception thrown by a smart service in the course of its execution. Throwing this exception is the mechanism by which a smart service alerts the process execution engine that the node has failed to complete successfully. The execution layer is then responsible for taking the appropriate action (pausing the node by exception, displaying an error message, sending an alert, etc.).

The Builder inner class can be used to easily create an exception that has an internationalized message text based on a key in the bundle file included with the smart service plug-in.

For example, your smart service class may include a method such as the following:
private SmartServiceException createException(Throwable t, String key, Object... args) { return new SmartServiceException.Builder(getClass(), t).userMessage(key, args).build(); }
and then when the smart service encounters an exception, throw createException(e,"error.my.message") where "error.my.message" is a key to an error message defined in the bundle.

See Also:
  • Field Details

    • alertMessageKey

      protected String alertMessageKey
    • alertMessageArgs

      protected Object[] alertMessageArgs
    • addCauseToAlertMessageArgs

      protected boolean addCauseToAlertMessageArgs
    • userMessageKey

      protected String userMessageKey
    • userMessageArgs

      protected Object[] userMessageArgs
    • addCauseToUserMessageArgs

      protected boolean addCauseToUserMessageArgs
  • Constructor Details

    • SmartServiceException

      public SmartServiceException(ErrorCode errorCode, Object... errorCodeArgs)
      Constructor to be used if the SmartServiceException has an error code associated with it.
      Parameters:
      errorCode - the error code associated with the exception
      errorCodeArgs - the parameters to the error code message
      See Also:
    • SmartServiceException

      public SmartServiceException(ErrorCode errorCode, Throwable cause, Object... errorCodeArgs)
      Constructor to be used if the SmartServiceException has an error code associated with it and the root cause of the exception is to be included.
      Parameters:
      errorCode - the error code associated with the exception
      cause - the cause of the exception
      errorCodeArgs - the parameters to the error code message
      See Also:
    • SmartServiceException

      public SmartServiceException(ErrorCode errorCode, Throwable cause)
      Constructor to be used if the SmartServiceException has an error code associated with it and the root cause of the exception is to be included.
      Parameters:
      errorCode - the error code associated with the exception
      cause - the cause of the exception
      See Also:
    • SmartServiceException

      public SmartServiceException(Class<? extends AppianSmartService> smartServiceClass, Throwable cause, String key, Object... args)
      Construct a SmartServiceException from all of its constituent parts. It's recommended to use the Builder inner class instead of this constructor.
      Parameters:
      smartServiceClass - the class that is throwing the exception
      cause - the Throwable that was caught, causing the SmartServiceException to be thrown
      key - the key to the error message in the bundle
      args - the set of paramaters that are passed with the error message to include dynamic information in the message if the value of the error bundle contains templates.
    • SmartServiceException

      protected SmartServiceException(SmartServiceException.Builder builder)
      Constructor that creates the SmartServiceException based on the Builder inner class. Instead of passing a Builder to this constructor use the Builder.build method.
      Parameters:
      builder - the instance of the Builder inner class on which the SmartServiceException should be based.
  • Method Details

    • getAlertMessage

      public String getAlertMessage(Locale locale)
      This method is called by the process execution layer to determine the message that should be shown in the body of the alert. If no message is defined for the preferred locale, it falls back to US.
      Returns:
      the text of the error message intended for the user
    • getAttendedUserMessage

      public String getAttendedUserMessage(Locale locale)
      This method is called by the process execution layer to determine the message that should be shown to the user in their locale. If no message is defined for their preferred locale, it falls back to US.
      Returns:
      the text of the error message intended for the user
    • getExceptionClassName

      public String getExceptionClassName()
      If the exception that caused this SmartServiceException is set, this method returns the name of that exception class, otherwise it will return null.
      Returns:
      the name of the exception or null
    • getCauseMessage

      protected String getCauseMessage(Locale locale)
    • getMessageFromBundle

      protected String getMessageFromBundle(String key, Object[] args, Locale locale)
    • toString

      public String toString()
      Description copied from class: AppianException
      Returns a detailed exception's message representation. This method should not be used to display messages to the end user. The default representation includes the exception class name, the exception's message as returned by AppianException.getMessage() and the error code associated with this exception. If the error code is ErrorCode.GENERIC_ERROR, no error code information is included.
      Overrides:
      toString in class AppianException