Package com.sap.cds.services
Class ServiceException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.sap.cds.services.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
Modifier and TypeFieldDescriptionprotected final Object[]
protected final ErrorStatus
protected MessageTarget
protected static ServiceExceptionUtils
-
Constructor Summary
ConstructorDescriptionServiceException
(ErrorStatus errorStatus, String message, Object... args) Creates a newServiceException
ServiceException
(String message, Object... args) Creates a newServiceException
.Creates a newServiceException
TheErrorStatus
of the firstServiceException
found within the cause chain is used. -
Method Summary
Modifier and TypeMethodDescriptionprotected List<EventContext>
Returns the stack ofEventContext
which corresponds to the events processed along the exception stack trace.getLocalizedMessage
(Locale locale) 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.messageTarget
(MessageTarget target) Sets the provided message target.<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
.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
errorStatus
-
messageTarget
-
args
-
Utils
-
-
Constructor Details
-
ServiceException
Creates a newServiceException
TheErrorStatus
of the firstServiceException
found within the cause chain is used. If noErrorStatus
is found, it defaults toErrorStatuses.SERVER_ERROR
.- Parameters:
e
- The causingThrowable
-
ServiceException
Creates a newServiceException
. The last argument might be the causingThrowable
and not a formatting argument.
TheErrorStatus
of the firstServiceException
found within the cause chain is used. If noErrorStatus
is found, it defaults toErrorStatuses.SERVER_ERROR
.- Parameters:
message
- The formatting message, based on SLF4J'sMessageFormatter
args
- The arguments to the formatting message. The last argument might the causingThrowable
.
-
ServiceException
Creates a newServiceException
- Parameters:
errorStatus
- TheErrorStatus
, ifnull
theErrorStatus
of the firstServiceException
found within the cause chain is used. If noErrorStatus
is found, it defaults toErrorStatuses.SERVER_ERROR
message
- The formatting message, based on SLF4J'sMessageFormatter
args
- The arguments to the formatting message. The last argument might the causingThrowable
.
-
-
Method Details
-
getErrorStatus
- Returns:
- the
ErrorStatus
-
getMessageTarget
- Returns:
- the
MessageTarget
-
getMessage
- Overrides:
getMessage
in classThrowable
-
getLocalizedMessage
- Overrides:
getLocalizedMessage
in classThrowable
-
getLocalizedMessage
-
getPlainMessage
- Returns:
- The original message of this exception
-
getEventContexts
Returns the stack ofEventContext
which corresponds to the events processed along the exception stack trace. The lists starts with theEventContext
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
-
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
Sets the provided message target.- Parameters:
target
- the message 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 callingmessageTarget(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_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 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 callingmessageTarget(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_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 pathelement
- the cds element- Returns:
- The current
ServiceException
-