Package org.springframework.http
Class ProblemDetail
java.lang.Object
org.springframework.http.ProblemDetail
Representation of an RFC 7807 problem detail, including all RFC-defined
fields. For an extended response with more fields, create a subclass that
exposes the additional fields.
- Since:
- 6.0
- Author:
- Rossen Stoyanchev
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
For deserialization.protected
ProblemDetail
(int rawStatusCode) Protected constructor for subclasses.protected
ProblemDetail
(ProblemDetail other) Copy constructor that could be used from a subclass to re-create aProblemDetail
in order to extend it with more fields. -
Method Summary
Modifier and TypeMethodDescriptionstatic ProblemDetail
forStatus
(int status) Create aProblemDetail
instance with the given status value.static ProblemDetail
forStatus
(HttpStatusCode status) Create aProblemDetail
instance with the given status code.Return the configuredproblem detail
.Return the configuredproblem instance
.int
Return the status associated with the problem, provided either to the constructor or configured viasetStatus(int)
.getTitle()
Return the configuredproblem title
.getType()
Return the configuredproblem type
.protected String
Return a String representation of theProblemDetail
fields.void
Setter for theproblem detail
.void
setInstance
(URI instance) Setter for theproblem instance
.void
setStatus
(int status) Setter for theproblem status
.void
Setter for theproblem title
.void
Setter for theproblem type
.toString()
withDetail
(String detail) Variant ofsetDetail(String)
for chained initialization.withInstance
(URI instance) Variant ofsetInstance(URI)
for chained initialization.withStatus
(int status) Variant ofsetStatus(int)
for chained initialization.withStatus
(HttpStatusCode statusCode) Variant ofsetStatus(int)
for chained initialization.Variant ofsetTitle(String)
for chained initialization.Variant ofsetType(URI)
for chained initialization.
-
Constructor Details
-
ProblemDetail
protected ProblemDetail(int rawStatusCode) Protected constructor for subclasses.To create a
ProblemDetail
instance, use static factory methods,forStatus(HttpStatusCode)
orforStatus(int)
.- Parameters:
rawStatusCode
- the response status to use
-
ProblemDetail
Copy constructor that could be used from a subclass to re-create aProblemDetail
in order to extend it with more fields. -
ProblemDetail
protected ProblemDetail()For deserialization.
-
-
Method Details
-
withType
Variant ofsetType(URI)
for chained initialization.- Parameters:
type
- the problem type- Returns:
- the same instance
-
withTitle
Variant ofsetTitle(String)
for chained initialization.- Parameters:
title
- the problem title- Returns:
- the same instance
-
withStatus
Variant ofsetStatus(int)
for chained initialization.- Parameters:
statusCode
- the response status for the problem- Returns:
- the same instance
-
withStatus
Variant ofsetStatus(int)
for chained initialization.- Parameters:
status
- the response status value for the problem- Returns:
- the same instance
-
withDetail
Variant ofsetDetail(String)
for chained initialization.- Parameters:
detail
- the problem detail- Returns:
- the same instance
-
withInstance
Variant ofsetInstance(URI)
for chained initialization.- Parameters:
instance
- the problem instance URI- Returns:
- the same instance
-
setType
Setter for theproblem type
.By default, this is
BLANK_TYPE
.- Parameters:
type
- the problem type- See Also:
-
setTitle
Setter for theproblem title
.By default, if not explicitly set and the status is well-known, this is sourced from the
HttpStatus.getReasonPhrase()
.- Parameters:
title
- the problem title- See Also:
-
setStatus
public void setStatus(int status) Setter for theproblem status
.- Parameters:
status
- the problem status- See Also:
-
setDetail
Setter for theproblem detail
.By default, this is not set.
- Parameters:
detail
- the problem detail- See Also:
-
setInstance
Setter for theproblem instance
.By default, when
ProblemDetail
is returned from an@ExceptionHandler
method, this is initialized to the request path.- Parameters:
instance
- the problem instance- See Also:
-
getType
Return the configuredproblem type
. -
getTitle
Return the configuredproblem title
. -
getStatus
public int getStatus()Return the status associated with the problem, provided either to the constructor or configured viasetStatus(int)
. -
getDetail
Return the configuredproblem detail
. -
getInstance
Return the configuredproblem instance
. -
toString
-
initToStringContent
Return a String representation of theProblemDetail
fields. Subclasses can override this to append additional fields. -
forStatus
Create aProblemDetail
instance with the given status code. -
forStatus
Create aProblemDetail
instance with the given status value.
-