public class ResourceException extends IOException implements Response
Positive 3-digit integer exception codes are explicitly reserved for exceptions that correspond with HTTP status codes. For the sake of interoperability with HTTP, if an exception corresponds with an HTTP error status, use the matching HTTP status code.
Modifier and Type | Field and Description |
---|---|
static int |
BAD_REQUEST
Indicates that the request could not be understood by the resource due to
malformed syntax.
|
static int |
CONFLICT
Indicates the request could not be completed due to a conflict with the
current state of the resource.
|
static String |
FIELD_CAUSE
The name of the JSON field used for the cause message.
|
static String |
FIELD_CODE
The name of the JSON field used for the code.
|
static String |
FIELD_DETAIL
The name of the JSON field used for the detail.
|
static String |
FIELD_MESSAGE
The name of the JSON field used for the message.
|
static String |
FIELD_REASON
The name of the JSON field used for the reason.
|
static int |
FORBIDDEN
Indicates that the resource understood the request, but is refusing to
fulfill it.
|
static int |
INTERNAL_ERROR
Indicates that a resource encountered an unexpected condition which
prevented it from fulfilling the request.
|
static int |
NOT_FOUND
Indicates that the resource could not be found.
|
static int |
NOT_SUPPORTED
Indicates that the resource does not implement/support the feature to
fulfill the request HTTP status: 501 Not Implemented.
|
static int |
UNAVAILABLE
Indicates that the resource is temporarily unable to handle the request.
|
static int |
VERSION_MISMATCH
Indicates that the resource's current version does not match the version
provided.
|
static int |
VERSION_REQUIRED
Indicates that the resource requires a version, but no version was
supplied in the request.
|
Modifier | Constructor and Description |
---|---|
protected |
ResourceException(int code)
Constructs a new exception with the specified exception code, and
null as its detail message. |
protected |
ResourceException(int code,
String message)
Constructs a new exception with the specified exception code and detail
message.
|
protected |
ResourceException(int code,
String message,
Throwable cause)
Constructs a new exception with the specified exception code, reason
phrase, detail message and cause.
|
protected |
ResourceException(int code,
Throwable cause)
Constructs a new exception with the specified exception code and detail
message.
|
Modifier and Type | Method and Description |
---|---|
<V> Promise<V,ResourceException> |
asPromise()
Return this ResourceException as a Promise.
|
int |
getCode()
Returns the numeric code of the exception.
|
JsonValue |
getDetail()
Returns the additional detail which can be evaluated by applications.
|
static ResourceException |
getException(int code)
Deprecated.
in favor of
ResourceException.newResourceException(int) |
static ResourceException |
getException(int code,
String message)
Deprecated.
|
static ResourceException |
getException(int code,
String message,
Throwable cause)
Deprecated.
|
String |
getReason()
Returns the short reason phrase of the exception.
|
Version |
getResourceApiVersion()
Gets the API version of the resource that the request was routed to.
|
<E extends ResourceException> |
includeCauseInJsonValue()
Returns this ResourceException with the includeCause flag set to true
so that toJsonValue() method will include the cause if there is
one supplied.
|
boolean |
isServerError()
Returns true if the HTTP error code is in the 500 range.
|
static ResourceException |
newResourceException(int code)
Returns an exception with the specified HTTP error code, but no detail
message or cause, and a default reason phrase.
|
static ResourceException |
newResourceException(int code,
String message)
Returns an exception with the specified HTTP error code and detail
message, but no cause, and a default reason phrase.
|
static ResourceException |
newResourceException(int code,
String message,
Throwable cause)
Returns an exception with the specified HTTP error code, detail message,
and cause, and a default reason phrase.
|
<E extends ResourceException> |
setDetail(JsonValue detail)
Sets the additional detail which can be evaluated by applications.
|
<E extends ResourceException> |
setReason(String reason)
Sets/overrides the short reason phrase of the exception.
|
void |
setResourceApiVersion(Version version)
Sets the API version of the resource that the request was routed to.
|
JsonValue |
toJsonValue()
Returns the exception in a JSON object structure, suitable for inclusion
in the entity of an HTTP error response.
|
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
public static final String FIELD_DETAIL
public static final String FIELD_MESSAGE
public static final String FIELD_REASON
public static final String FIELD_CODE
public static final String FIELD_CAUSE
public static final int BAD_REQUEST
public static final int CONFLICT
public static final int FORBIDDEN
public static final int INTERNAL_ERROR
public static final int NOT_FOUND
public static final int NOT_SUPPORTED
public static final int UNAVAILABLE
public static final int VERSION_MISMATCH
public static final int VERSION_REQUIRED
protected ResourceException(int code)
null
as its detail message. If the error code corresponds with a
known HTTP error status code, then the reason phrase is set to a
corresponding reason phrase, otherwise is set to a generic value
"Resource Exception"
.code
- The numeric code of the exception.protected ResourceException(int code, String message)
code
- The numeric code of the exception.message
- The detail message.protected ResourceException(int code, Throwable cause)
code
- The numeric code of the exception.cause
- The exception which caused this exception to be thrown.protected ResourceException(int code, String message, Throwable cause)
code
- The numeric code of the exception.message
- The detail message.cause
- The exception which caused this exception to be thrown.public static ResourceException newResourceException(int code)
ResourceException
.
If the type of the expected exception is known in advance, prefer to directly instantiate the exception type as usual:
throw new InternalServerErrorException("Server failed");
code
- The HTTP error code.public static ResourceException newResourceException(int code, String message)
ResourceException
.
If the type of the expected exception is known in advance, prefer to directly instantiate the exception type as usual:
throw new InternalServerErrorException("Server failed");
code
- The HTTP error code.message
- The detail message.public static ResourceException newResourceException(int code, String message, Throwable cause)
ResourceException
.
If the type of the expected exception is known in advance, prefer to directly instantiate the exception type as usual:
throw new InternalServerErrorException("Server failed");
code
- The HTTP error code.message
- The detail message.cause
- The exception which caused this exception to be thrown.@Deprecated public static ResourceException getException(int code)
ResourceException.newResourceException(int)
ResourceException
.code
- The HTTP error code.@Deprecated public static ResourceException getException(int code, String message)
ResourceException.newResourceException(int, String)
ResourceException
.code
- The HTTP error code.message
- The detail message.@Deprecated public static ResourceException getException(int code, String message, Throwable cause)
ResourceException.newResourceException(int, String, Throwable)
ResourceException
.code
- The HTTP error code.message
- The detail message.cause
- The exception which caused this exception to be thrown.public final int getCode()
public boolean isServerError()
true
if HTTP error code is in the 500 range.public final JsonValue getDetail()
getDetail().isNull() == true
), and it is the responsibility of
the resource provider to add it if needed.null
).public final String getReason()
public final <E extends ResourceException> E setDetail(JsonValue detail)
getDetail().isNull() == true
), and it is the responsibility of
the resource provider to add it if needed.E
- The ResourceException subtypedetail
- The additional detail which can be evaluated by applications.public final <E extends ResourceException> E setReason(String reason)
E
- The ResourceException subtypereason
- The short reason phrase of the exception.public final <E extends ResourceException> E includeCauseInJsonValue()
E
- The ResourceException subtypepublic final JsonValue toJsonValue()
{ "code" : 404, "reason" : "...", // optional "message" : "...", // required "detail" : { ... } // optional "cause" : { ... } // optional iff includeCause is set to true }
public void setResourceApiVersion(Version version)
Response
setResourceApiVersion
in interface Response
version
- The resource API version.public Version getResourceApiVersion()
Response
getResourceApiVersion
in interface Response
public <V> Promise<V,ResourceException> asPromise()
V
- the result value type of the promiseCopyright © 2010-2018, ForgeRock All Rights Reserved.