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.Modifier and Type | Field and Description |
---|---|
protected Object[] |
args |
protected ErrorStatus |
errorStatus |
protected MessageTarget |
messageTarget |
protected static ServiceExceptionUtils |
Utils |
Constructor and Description |
---|
ServiceException(ErrorStatus errorStatus,
String message,
Object... args)
Creates a new
ServiceException |
ServiceException(String message,
Object... args)
Creates a new
ServiceException . |
ServiceException(Throwable e)
Creates a new
ServiceException
The ErrorStatus of the first ServiceException found within the cause chain is used. |
Modifier and Type | Method and Description |
---|---|
ErrorStatus |
getErrorStatus() |
String |
getLocalizedMessage() |
String |
getLocalizedMessage(Locale locale) |
String |
getMessage() |
MessageTarget |
getMessageTarget() |
String |
getPlainMessage() |
<E extends com.sap.cds.ql.StructuredType<E>> |
messageTarget(Class<E> entity,
Function<E,Object> path)
Adds the passed root entity and CQN path as target to the current
ServiceException . |
ServiceException |
messageTarget(String target)
Sets the provided string-based target.
|
<E extends com.sap.cds.ql.StructuredType<E>> |
messageTarget(String prefix,
Class<E> entity,
Function<E,Object> path)
Adds the passed root entity and CQN path as target to the current
ServiceException . |
ServiceException |
messageTarget(String entity,
Function<com.sap.cds.ql.StructuredType<?>,Object> path)
Adds the passed root entity and CQN path as target to the current
ServiceException . |
ServiceException |
messageTarget(String prefix,
String entity,
Function<com.sap.cds.ql.StructuredType<?>,Object> path)
Adds the passed root entity and CQN path as target to the current
ServiceException . |
addSuppressed, fillInStackTrace, getCause, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
protected final ErrorStatus errorStatus
protected MessageTarget messageTarget
protected final Object[] args
protected static ServiceExceptionUtils Utils
public ServiceException(Throwable e)
ServiceException
ErrorStatus
of the first ServiceException
found within the cause chain is used.
If no ErrorStatus
is found, it defaults to ErrorStatuses.SERVER_ERROR
.e
- The causing Throwable
public ServiceException(String message, Object... args)
ServiceException
. The last argument might be the causing Throwable
and not a formatting argument.
ErrorStatus
of the first ServiceException
found within the cause chain is used.
If no ErrorStatus
is found, it defaults to ErrorStatuses.SERVER_ERROR
.message
- The formatting message, based on SLF4J's MessageFormatter
args
- The arguments to the formatting message. The last argument might the causing Throwable
.public ServiceException(ErrorStatus errorStatus, String message, Object... args)
ServiceException
errorStatus
- The ErrorStatus
, if null
the ErrorStatus
of the first ServiceException
found within the cause chain is used.
If no ErrorStatus
is found, it defaults to ErrorStatuses.SERVER_ERROR
message
- The formatting message, based on SLF4J's MessageFormatter
args
- The arguments to the formatting message. The last argument might the causing Throwable
.public ErrorStatus getErrorStatus()
ErrorStatus
public MessageTarget getMessageTarget()
MessageTarget
public String getMessage()
getMessage
in class Throwable
public String getLocalizedMessage()
getLocalizedMessage
in class Throwable
public String getPlainMessage()
public ServiceException messageTarget(String target)
target
- the string-based targetServiceException
public ServiceException messageTarget(String entity, Function<com.sap.cds.ql.StructuredType<?>,Object> path)
ServiceException
.entity
- the root entity of the pathpath
- the path to the target element or associationServiceException
public ServiceException messageTarget(String prefix, String entity, Function<com.sap.cds.ql.StructuredType<?>,Object> path)
ServiceException
.prefix
- the string-based prefix, prepended to the CQN pathentity
- the root entity of the pathpath
- the path to the target element or associationServiceException
public <E extends com.sap.cds.ql.StructuredType<E>> ServiceException messageTarget(Class<E> entity, Function<E,Object> path)
ServiceException
.E
- the entity typeentity
- the root entity of the pathpath
- the path to the target element or associationServiceException
public <E extends com.sap.cds.ql.StructuredType<E>> ServiceException messageTarget(String prefix, Class<E> entity, Function<E,Object> path)
ServiceException
.E
- the entity typeprefix
- the string-based prefix, prepended to the CQN pathentity
- the root entity of the pathpath
- the path to the target element or associationServiceException
Copyright © 2020. All rights reserved.