Class ServiceException
- All Implemented Interfaces:
Serializable
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final Object[]protected final ErrorStatusprotected static ServiceExceptionUtils -
Constructor Summary
ConstructorsConstructorDescriptionServiceException(ErrorStatus errorStatus, String messageOrKey, Object... args) Creates a newServiceExceptionServiceException(String messageOrKey, Object... args) Creates a newServiceException.Creates a newServiceException
TheErrorStatusof the firstServiceExceptionfound within the cause chain is used. -
Method Summary
Modifier and TypeMethodDescriptionadditionalTargets(MessageTarget... additionalTargets) Sets the provided array ofMessageTargetinstances as additional targets.additionalTargets(List<MessageTarget> additionalTargets) Sets the provided list ofMessageTargetinstances as additional targets.protected List<EventContext>Returns the stack ofEventContextwhich corresponds to the events processed along the exception stack trace.getLocalizedMessage(Locale locale) booleanReturnstrue, if the transition indicator is set for this exception.longTextUrl(String longTextUrl) Adds the passedlongTextUrlto the current exception.messageTarget(com.sap.cds.ql.cqn.Path path, com.sap.cds.reflect.CdsElement element) Adds the passed path and element as target to the currentServiceException.messageTarget(MessageTarget target) Sets the providedMessageTarget<E extends com.sap.cds.ql.StructuredType<E>>
ServiceExceptionmessageTarget(Class<E> type, Function<E, Object> path) Adds the passed path as target to the currentServiceException.messageTarget(String target) Sets the provided string-based target.<E extends com.sap.cds.ql.StructuredType<E>>
ServiceExceptionmessageTarget(String parameter, Class<E> type, Function<E, Object> path) Adds the passed target parameter and path as target to the currentServiceException.messageTarget(String parameter, Function<com.sap.cds.ql.StructuredType<?>, Object> path) Adds the passed target parameter and path as target to the currentServiceException.messageTarget(Function<com.sap.cds.ql.StructuredType<?>, Object> path) Adds the passed path as target to the currentServiceException.transition(boolean isTransition) Sets thetransitionindicator of this exception.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
errorStatus
-
args
-
Utils
-
-
Constructor Details
-
ServiceException
Creates a newServiceException
TheErrorStatusof the firstServiceExceptionfound within the cause chain is used. If noErrorStatusis found, it defaults toErrorStatuses.SERVER_ERROR.- Parameters:
e- The causingThrowable
-
ServiceException
Creates a newServiceException. The last argument might be the causingThrowableand not a formatting argument.
TheErrorStatusof the firstServiceExceptionfound within the cause chain is used. If noErrorStatusis found, it defaults toErrorStatuses.SERVER_ERROR.- Parameters:
messageOrKey- The formatting message, based on SLF4J'sMessageFormatter, or a key to a message format in the resource bundles.args- The argument objects for the format string. The last argument might be the causingThrowable.
-
ServiceException
Creates a newServiceException- Parameters:
errorStatus- TheErrorStatus, ifnulltheErrorStatusof the firstServiceExceptionfound within the cause chain is used. If noErrorStatusis found, it defaults toErrorStatuses.SERVER_ERRORmessageOrKey- The formatting message, based on SLF4J'sMessageFormatter, or a key to a message format in the resource bundles.args- The argument objects for the format string. The last argument might be the causingThrowable.
-
-
Method Details
-
getMessage
- Overrides:
getMessagein classThrowable
-
getLocalizedMessage
- Overrides:
getLocalizedMessagein classThrowable
-
getLocalizedMessage
-
getPlainMessage
- Returns:
- The original message of this exception
-
getEventContexts
Returns the stack ofEventContextwhich corresponds to the events processed along the exception stack trace. The lists starts with theEventContextfrom which the exception was triggered. If there are no contexts, the method returns an empty list- Returns:
- the stack of
EventContextwhich corresponds to the events processed along the exception stack trace.
-
collectEventContexts
-
getErrorStatus
- Returns:
- the
ErrorStatus
-
getMessageLookup
- Returns:
- the
MessageLookup
-
getLongTextUrl
- Returns:
- the long text url
-
getMessageTarget
- Returns:
- the
MessageTarget
-
getAdditionalTargets
- Returns:
- the list of additional
MessageTargetinstances
-
isTransition
public boolean isTransition()Returnstrue, 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
Adds the passedlongTextUrlto the current exception.- Parameters:
longTextUrl- The long text url to be set- Returns:
- The current
ServiceException
-
transition
Sets thetransitionindicator 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
Sets the providedMessageTarget- Parameters:
target- theMessageTarget- Returns:
- The current
ServiceException
-
messageTarget
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
Adds the passed path as target to the currentServiceException.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 currentServiceException.- Parameters:
parameter- target parameter serving as the entry point for the path resolution. PassingMessageTarget.PARAMETER_CQNindicates 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 currentServiceException. 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 currentServiceException. 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. PassingMessageTarget.PARAMETER_CQNindicates 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 currentServiceException.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
CdsDataProcessorand its functional interfaces.- Parameters:
path- the pathelement- the target element or association- Returns:
- The current
ServiceException
-
additionalTargets
Sets the provided list ofMessageTargetinstances as additional targets.- Parameters:
additionalTargets- the list of additionalMessageTargetinstances.- Returns:
- The current
ServiceException
-
additionalTargets
Sets the provided array ofMessageTargetinstances as additional targets.- Parameters:
additionalTargets- the array of additionalMessageTargetinstances.- Returns:
- The current
ServiceException
-