Class ApiError
java.lang.Object
com.broadleafcommerce.common.error.ApiError
- Direct Known Subclasses:
ApiValidationError
Response object that represents some error state from the API. Intended use is to wrap this
within a
ResponseEntity to return from an ExceptionHandler.- Author:
- Phillip Verheyden (phillipuniverse)
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionApiError(String type, String title, String exception, OffsetDateTime timestamp, org.springframework.http.HttpStatusCode status, int statusCode, List<GlobalError> globalErrors) Initializes a new error -
Method Summary
Modifier and TypeMethodDescriptionvoidaddError(GlobalError error) Gives more information to a client about what went wrong in their requestOptional exception class nameOptionally gives additional information to the client about what was wrong with their requestorg.springframework.http.HttpStatusintNumerical representation ofstatusWhen the error occurred, defaults toLocalDateTime.now()getTitle()A human-readable representation of the type of error being returnedgetType()A machine-readable representation of the type of error being returnedvoidsetException(String exception) Optional exception class namevoidsetTimestamp(OffsetDateTime timestamp) When the error occurred, defaults toLocalDateTime.now()org.springframework.http.ResponseEntity<ApiError>toString()withException(String exception) Optional exception class namewithGlobalErrors(List<GlobalError> globalErrors) Optionally gives additional information to the client about what was wrong with their requestwithStatus(org.springframework.http.HttpStatusCode status) Should always match exactly the status in the response header.withStatusCode(int statusCode) Numerical representation ofstatuswithTimestamp(OffsetDateTime timestamp) When the error occurred, defaults toLocalDateTime.now()A human-readable representation of the type of error being returnedA machine-readable representation of the type of error being returned
-
Constructor Details
-
ApiError
Initializes a new error- Parameters:
type- a machine-readable representation of this errortitle- a human-readable representation of the errorstatus- HTTP status
-
ApiError
-
ApiError
public ApiError(String type, String title, String exception, OffsetDateTime timestamp, org.springframework.http.HttpStatusCode status, int statusCode, List<GlobalError> globalErrors)
-
-
Method Details
-
toResponseEntity
-
addError
Gives more information to a client about what went wrong in their request- Parameters:
error- the error to add to this response
-
getStatus
public org.springframework.http.HttpStatus getStatus() -
getType
A machine-readable representation of the type of error being returned -
getTitle
A human-readable representation of the type of error being returned -
getException
Optional exception class name -
getTimestamp
When the error occurred, defaults toLocalDateTime.now() -
getStatusCode
public int getStatusCode()Numerical representation ofstatus -
getGlobalErrors
Optionally gives additional information to the client about what was wrong with their request- See Also:
-
toString
-
withType
A machine-readable representation of the type of error being returned- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withTitle
A human-readable representation of the type of error being returned- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withException
Optional exception class name- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withTimestamp
When the error occurred, defaults toLocalDateTime.now()- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withStatus
Should always match exactly the status in the response header. Makes it easier to parse out and log- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withStatusCode
Numerical representation ofstatus- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withGlobalErrors
Optionally gives additional information to the client about what was wrong with their request- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed). - See Also:
-
setException
Optional exception class name -
setTimestamp
When the error occurred, defaults toLocalDateTime.now()
-