Class ServiceException

All Implemented Interfaces:
Serializable

public class ServiceException extends RuntimeException
ServiceException is the central unchecked exception thrown by the framework and Handler when an error occurs during event processing via Service.emit(EventContext) It extends RuntimeException with an ErrorStatus, which indicates an internal error code and a mapping to an HTTP status code.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getMessage

      public String getMessage()
      Overrides:
      getMessage in class Throwable
    • getLocalizedMessage

      public String getLocalizedMessage()
      Overrides:
      getLocalizedMessage in class Throwable
    • getLocalizedMessage

      public String getLocalizedMessage(Locale locale)
    • getPlainMessage

      public String getPlainMessage()
      Returns:
      The original message of this exception
    • getEventContexts

      public List<EventContext> getEventContexts()
      Returns the stack of EventContext which corresponds to the events processed along the exception stack trace. The lists starts with the EventContext from which the exception was triggered. If there are no contexts, the method returns an empty list
      Returns:
      the stack of EventContext which corresponds to the events processed along the exception stack trace.
    • collectEventContexts

      protected List<EventContext> collectEventContexts()
    • getErrorStatus

      public ErrorStatus getErrorStatus()
      Returns:
      the ErrorStatus
    • getMessageLookup

      public MessageLookup getMessageLookup()
      Returns:
      the MessageLookup
    • getLongTextUrl

      public String getLongTextUrl()
      Returns:
      the long text url
    • getMessageTarget

      public MessageTarget getMessageTarget()
      Returns:
      the MessageTarget
    • getAdditionalTargets

      public List<MessageTarget> getAdditionalTargets()
      Returns:
      the list of additional MessageTarget instances
    • isTransition

      public boolean isTransition()
      Returns true, if the transition indicator is set for this exception.

      A transition message is a request-specific message, that is valid during the runtime of a request. It might not reoccur if the same request is processed again. A state message has a relation to an entity document. It is typically a validation (error) message.

      Returns:
      true, if the transition indicator is set for this exception
    • longTextUrl

      public ServiceException longTextUrl(String longTextUrl)
      Adds the passed longTextUrl to the current exception.
      Parameters:
      longTextUrl - The long text url to be set
      Returns:
      The current ServiceException
    • transition

      public ServiceException transition(boolean isTransition)
      Sets the transition indicator of this exception.

      A transition message is a request-specific message, that is valid during the runtime of a request. It might not reoccur if the same request is processed again. A state message has a relation to an entity document. It is typically a validation (error) message.

      Parameters:
      isTransition - true, if the transition indicator should be set, false, if it should be unset
      Returns:
      The current ServiceException
    • messageTarget

      public ServiceException messageTarget(MessageTarget target)
      Sets the provided MessageTarget
      Parameters:
      target - the MessageTarget
      Returns:
      The current ServiceException
    • messageTarget

      public ServiceException messageTarget(String target)
      Sets the provided string-based target. No further processing of the string is performed.
      Parameters:
      target - the string-based target
      Returns:
      The current ServiceException
    • messageTarget

      public ServiceException messageTarget(Function<com.sap.cds.ql.StructuredType<?>,Object> path)
      Adds the passed path as target to the current ServiceException.

      The path is interpreted relative to the CQN statement, which was determined from the request. For CRUD events this CQN statement points to the targeted entity. For bound actions or functions this CQN statement points to the bound entity.

      Is equivalent to calling messageTarget(MessageTarget.PARAMETER_CQN, path)

      Parameters:
      path - the path to the target element or association
      Returns:
      The current ServiceException
    • messageTarget

      public ServiceException messageTarget(String parameter, Function<com.sap.cds.ql.StructuredType<?>,Object> path)
      Adds the passed target parameter and path as target to the current ServiceException.
      Parameters:
      parameter - target parameter serving as the entry point for the path resolution. Passing MessageTarget.PARAMETER_CQN indicates that the path should be interpreted relatively to the target entity of the request. Alternatively you can pass names of action or function parameters.
      path - the path to the target element or association
      Returns:
      The current ServiceException
    • messageTarget

      public <E extends com.sap.cds.ql.StructuredType<E>> ServiceException messageTarget(Class<E> type, Function<E,Object> path)
      Adds the passed path as target to the current ServiceException. This method allows to build the path in a type-safe way, by passing the corresponding entity or structured type interface.

      The path is interpreted relative to the CQN statement, which was determined from the request. For CRUD events this CQN statement points to the targeted entity. For bound actions or functions this CQN statement points to the bound entity.

      Is equivalent to calling messageTarget(MessageTarget.PARAMETER_CQN, type, path)

      Type Parameters:
      E - the type of the root
      Parameters:
      type - the root type of the path. Either an entity or a structured type.
      path - the path to the target element or association
      Returns:
      The current ServiceException
    • messageTarget

      public <E extends com.sap.cds.ql.StructuredType<E>> ServiceException messageTarget(String parameter, Class<E> type, Function<E,Object> path)
      Adds the passed target parameter and path as target to the current ServiceException. This method allows to build the path in a type-safe way, by passing the corresponding entity or structured type interface.
      Type Parameters:
      E - the type of the root
      Parameters:
      parameter - target parameter serving as the entry point for the path resolution. Passing MessageTarget.PARAMETER_CQN indicates that the path should be interpreted relatively to the target entity of the request. Alternatively you can pass names of action or function parameters.
      type - the root type of the path. Either an entity or a structured type.
      path - the path to the target element or association
      Returns:
      The current ServiceException
    • messageTarget

      public ServiceException messageTarget(com.sap.cds.ql.cqn.Path path, com.sap.cds.reflect.CdsElement element)
      Adds the passed path and element as target to the current ServiceException.

      The path is interpreted relative to the CQN statement, which was determined from the request. For CRUD events this CQN statement points to the targeted entity. For bound actions or functions this CQN statement points to the bound entity.

      This method can be used with the CdsDataProcessor and its functional interfaces.

      Parameters:
      path - the path
      element - the target element or association
      Returns:
      The current ServiceException
    • additionalTargets

      public ServiceException additionalTargets(List<MessageTarget> additionalTargets)
      Sets the provided list of MessageTarget instances as additional targets.
      Parameters:
      additionalTargets - the list of additional MessageTarget instances.
      Returns:
      The current ServiceException
    • additionalTargets

      public ServiceException additionalTargets(MessageTarget... additionalTargets)
      Sets the provided array of MessageTarget instances as additional targets.
      Parameters:
      additionalTargets - the array of additional MessageTarget instances.
      Returns:
      The current ServiceException