Package com.nimbusds.oauth2.sdk
Class ErrorObject
- java.lang.Object
-
- com.nimbusds.oauth2.sdk.ErrorObject
-
- Direct Known Subclasses:
BearerTokenError
@Immutable public class ErrorObject extends Object
Error object, used to encapsulate OAuth 2.0 and other errors.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" }
-
-
Constructor Summary
Constructors Constructor Description ErrorObject(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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ErrorObject
appendDescription(String text)
Appends the specified text to the error description.boolean
equals(Object object)
String
getCode()
Gets the error code.String
getDescription()
Gets the error description.int
getHTTPStatusCode()
Gets the HTTP status code.URI
getURI()
Gets the error page URI.int
hashCode()
static ErrorObject
parse(HTTPResponse httpResponse)
Parses an error object from the specified HTTP response.static ErrorObject
parse(Map<String,List<String>> params)
Parses an error object from the specified parameters representation.static ErrorObject
parse(net.minidev.json.JSONObject jsonObject)
Parses an error object from the specified JSON object.ErrorObject
setDescription(String description)
Sets the error description.ErrorObject
setHTTPStatusCode(int httpStatusCode)
Sets the HTTP status code.ErrorObject
setURI(URI uri)
Sets the error page URI.net.minidev.json.JSONObject
toJSONObject()
Returns a JSON object representation of this error object.Map<String,List<String>>
toParameters()
Returns a parameters representation of this error object.String
toString()
-
-
-
Constructor Detail
-
ErrorObject
public ErrorObject(String code)
Creates a new error with the specified code.- Parameters:
code
- The error code,null
if not specified.
-
ErrorObject
public ErrorObject(String code, String description)
Creates a new error with the specified code and description.- Parameters:
code
- The error code,null
if not specified.description
- The error description,null
if not specified.
-
ErrorObject
public ErrorObject(String code, String description, int httpStatusCode)
Creates a new error with the specified code, description and HTTP status code.- Parameters:
code
- The error code,null
if not specified.description
- The error description,null
if not specified.httpStatusCode
- The HTTP status code, zero if not specified.
-
ErrorObject
public ErrorObject(String code, String description, int httpStatusCode, URI uri)
Creates a new error with the specified code, description, HTTP status code and page URI.- Parameters:
code
- The error code,null
if not specified.description
- The error description,null
if not specified.httpStatusCode
- The HTTP status code, zero if not specified.uri
- The error page URI,null
if not specified.
-
-
Method Detail
-
getCode
public String getCode()
Gets the error code.- Returns:
- The error code,
null
if not specified.
-
getDescription
public String getDescription()
Gets the error description.- Returns:
- The error description,
null
if not specified.
-
setDescription
public ErrorObject setDescription(String description)
Sets the error description.- Parameters:
description
- The error description,null
if not specified.- Returns:
- A copy of this error with the specified description.
-
appendDescription
public ErrorObject appendDescription(String text)
Appends the specified text to the error description.- Parameters:
text
- The text to append to the error description,null
if not specified.- Returns:
- A copy of this error with the specified appended description.
-
getHTTPStatusCode
public int getHTTPStatusCode()
Gets the HTTP status code.- Returns:
- The HTTP status code, zero if not specified.
-
setHTTPStatusCode
public ErrorObject setHTTPStatusCode(int httpStatusCode)
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
public URI getURI()
Gets the error page URI.- Returns:
- The error page URI,
null
if not specified.
-
setURI
public ErrorObject setURI(URI uri)
Sets the error page URI.- Parameters:
uri
- The error page URI,null
if not specified.- Returns:
- A copy of this error with the specified page URI.
-
toJSONObject
public net.minidev.json.JSONObject 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
public Map<String,List<String>> toParameters()
Returns a parameters representation of this error object. Suitable for URL-encoded error responses.- Returns:
- The parameters.
-
parse
public static ErrorObject parse(net.minidev.json.JSONObject jsonObject)
Parses an error object from the specified JSON object.- Parameters:
jsonObject
- The JSON object to parse. Must not benull
.- Returns:
- The error object.
-
parse
public static ErrorObject parse(Map<String,List<String>> params)
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
public static ErrorObject parse(HTTPResponse httpResponse)
Parses an error object from the specified HTTP response.- Parameters:
httpResponse
- The HTTP response to parse. Must not benull
.- Returns:
- The error object.
-
-