Package com.nimbusds.oauth2.sdk
Class ErrorObject
java.lang.Object
com.nimbusds.oauth2.sdk.ErrorObject
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
FederationAPIError,TokenSchemeError
Error object, used to encapsulate OAuth 2.0 and other errors. Supports
custom parameters.
Example error object as HTTP response:
HTTP/1.1 400 Bad Request
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"error" : "invalid_request"
}
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionErrorObject(String code) Creates a new error with the specified code.ErrorObject(String code, String description) Creates a new error with the specified code and description.ErrorObject(String code, String description, int httpStatusCode) Creates a new error with the specified code, description and HTTP status code.ErrorObject(String code, String description, int httpStatusCode, URI uri) Creates a new error with the specified code, description, HTTP status code and page URI.ErrorObject(String code, String description, int httpStatusCode, URI uri, Map<String, String> customParams) Creates a new error with the specified code, description, HTTP status code and page URI. -
Method Summary
Modifier and TypeMethodDescriptionappendDescription(String text) Appends the specified text to the error description.booleangetCode()Returns the error code.Returns the custom parameters.Returns the error description.intReturns the HTTP status code.getURI()Returns the error page URI.inthashCode()static booleanisLegal(char c) Returnstrueif the specified char is within the legal ranges [0x20, 0x21] | [0x23 - 0x5B] | [0x5D - 0x7E] for OAuth 2.0 error codes and messages.static booleanReturnstrueif the characters in the specified string are within thelegal rangesfor OAuth 2.0 error codes and messages.static ErrorObjectparse(HTTPResponse httpResponse) Parses an error object from the specified HTTP response.static ErrorObjectParses an error object from the specified parameters' representation.static ErrorObjectparse(net.minidev.json.JSONObject jsonObject) Parses an error object from the specified JSON object.static StringRemoves any characters from the specified string that are not within thelegal rangefor OAuth 2.0 error codes and messages.setCustomParams(Map<String, String> customParams) Sets the custom parameters.setDescription(String description) Sets the error description.setHTTPStatusCode(int httpStatusCode) Sets the HTTP status code.Sets the error page URI.Returns an HTTP response for this error object.net.minidev.json.JSONObjectReturns a JSON object representation of this error object.Returns a parameters representation of this error object.toString()
-
Constructor Details
-
ErrorObject
Creates a new error with the specified code. The code must be within thelegalcharacter range.- Parameters:
code- The error code,nullif not specified.
-
ErrorObject
Creates a new error with the specified code and description. The code and the description must be within thelegalcharacter range.- Parameters:
code- The error code,nullif not specified.description- The error description,nullif not specified.
-
ErrorObject
Creates a new error with the specified code, description and HTTP status code. The code and the description must be within thelegalcharacter range.- Parameters:
code- The error code,nullif not specified.description- The error description,nullif not specified.httpStatusCode- The HTTP status code, zero if not specified.
-
ErrorObject
Creates a new error with the specified code, description, HTTP status code and page URI. The code and the description must be within thelegalcharacter range.- Parameters:
code- The error code,nullif not specified.description- The error description,nullif not specified.httpStatusCode- The HTTP status code, zero if not specified.uri- The error page URI,nullif not specified.
-
ErrorObject
public ErrorObject(String code, String description, int httpStatusCode, URI uri, Map<String, String> customParams) Creates a new error with the specified code, description, HTTP status code and page URI. The code and the description must be within thelegalcharacter range.- Parameters:
code- The error code,nullif not specified.description- The error description,nullif not specified.httpStatusCode- The HTTP status code, zero if not specified.uri- The error page URI,nullif not specified.customParams- Custom parameters,nullif none.
-
-
Method Details
-
getCode
Returns the error code.- Returns:
- The error code,
nullif not specified.
-
getDescription
Returns the error description.- Returns:
- The error description,
nullif not specified.
-
setDescription
Sets the error description.- Parameters:
description- The error description,nullif not specified.- Returns:
- A copy of this error with the specified description.
-
appendDescription
Appends the specified text to the error description.- Parameters:
text- The text to append to the error description,nullif not specified.- Returns:
- A copy of this error with the specified appended description.
-
getHTTPStatusCode
Returns the HTTP status code.- Returns:
- The HTTP status code, zero if not specified.
-
setHTTPStatusCode
Sets the HTTP status code.- Parameters:
httpStatusCode- The HTTP status code, zero if not specified.- Returns:
- A copy of this error with the specified HTTP status code.
-
getURI
Returns the error page URI.- Returns:
- The error page URI,
nullif not specified.
-
setURI
Sets the error page URI.- Parameters:
uri- The error page URI,nullif not specified.- Returns:
- A copy of this error with the specified page URI.
-
getCustomParams
Returns the custom parameters.- Returns:
- The custom parameters, empty map if none.
-
setCustomParams
Sets the custom parameters.- Parameters:
customParams- The custom parameters,nullif none.- Returns:
- A copy of this error with the specified custom parameters.
-
toJSONObject
Returns a JSON object representation of this error object.Example:
{ "error" : "invalid_grant", "error_description" : "Invalid resource owner credentials" }- Returns:
- The JSON object.
-
toParameters
Returns a parameters representation of this error object. Suitable for URL-encoded error responses.- Returns:
- The parameters.
-
toHTTPResponse
Returns an HTTP response for this error object. If no HTTP status code is specified it will be set to 400 (Bad Request). If an error code is specified theContent-Typeheader will be set toapplication/json; charset=UTF-8and the error JSON object will be put in the entity body.- Returns:
- The HTTP response.
-
toString
-
hashCode
-
equals
-
parse
Parses an error object from the specified JSON object.- Parameters:
jsonObject- The JSON object to parse. Must not benull.- Returns:
- The error object.
-
parse
Parses an error object from the specified parameters' representation. Suitable for URL-encoded error responses.- Parameters:
params- The parameters. Must not benull.- Returns:
- The error object.
-
parse
Parses an error object from the specified HTTP response.- Parameters:
httpResponse- The HTTP response to parse. Must not benull.- Returns:
- The error object.
-
removeIllegalChars
Removes any characters from the specified string that are not within thelegal rangefor OAuth 2.0 error codes and messages.See RFC 6749, section 5.2.
- Parameters:
s- The string to check. May benull.- Returns:
- The string with removed illegal characters,
nullif the original string wasnull.
-
isLegal
Returnstrueif the characters in the specified string are within thelegal rangesfor OAuth 2.0 error codes and messages.See RFC 6749, section 5.2.
- Parameters:
s- The string to check. May benull.- Returns:
trueif the string is legal, elsefalse.
-
isLegal
Returnstrueif the specified char is within the legal ranges [0x20, 0x21] | [0x23 - 0x5B] | [0x5D - 0x7E] for OAuth 2.0 error codes and messages.See RFC 6749, section 5.2.
- Parameters:
c- The character to check. Must not benull.- Returns:
trueif the character is legal, elsefalse.
-