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

    • getErrorStatus

      public ErrorStatus getErrorStatus()
      Returns:
      the ErrorStatus
    • getMessageTarget

      public MessageTarget getMessageTarget()
      Returns:
      the MessageTarget
    • 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()
    • 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(MessageTarget target)
      Sets the provided message target.
      Parameters:
      target - the message 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)
      Sets the message target based on the provided path and cds element.
      Parameters:
      path - the target path
      element - the cds element
      Returns:
      The current ServiceException