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, String errorRef, String traceId, List<GlobalError> globalErrors) Creates a newApiErrorinstance.ApiError(String type, String title, String exception, OffsetDateTime timestamp, org.springframework.http.HttpStatus 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 requestUnique reference code for support and logs correlationOptional 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 returnedAPM trace ID for tracing the request across microservicesgetType()A machine-readable representation of the type of error being returnedvoidsetErrorRef(String errorRef) Unique reference code for support and logs correlationvoidsetException(String exception) Optional exception class namevoidsetTimestamp(OffsetDateTime timestamp) When the error occurred, defaults toLocalDateTime.now()voidsetTraceId(String traceId) APM trace ID for tracing the request across microservicesorg.springframework.http.ResponseEntity<ApiError>toString()withErrorRef(String errorRef) Unique reference code for support and logs correlationwithException(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 returnedwithTraceId(String traceId) APM trace ID for tracing the request across microservicesA 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.HttpStatus status, int statusCode, List<GlobalError> globalErrors) -
ApiError
public ApiError(String type, String title, String exception, OffsetDateTime timestamp, org.springframework.http.HttpStatusCode status, int statusCode, String errorRef, String traceId, List<GlobalError> globalErrors) Creates a newApiErrorinstance.- Parameters:
type- A machine-readable representation of the type of error being returnedtitle- A human-readable representation of the type of error being returnedexception- Optional exception class nametimestamp- When the error occurred, defaults toLocalDateTime.now()status- Should always match exactly the status in the response header. Makes it easier to parse out and logstatusCode- Numerical representation ofstatuserrorRef- Unique reference code for support and logs correlationtraceId- APM trace ID for tracing the request across microservicesglobalErrors- Optionally gives additional information to the client about what was wrong with their request- Since:
- Common Error 3.0.0, Common Error 3.0.0
- See Also:
-
-
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 -
getErrorRef
Unique reference code for support and logs correlation- Since:
- Common Error 3.0.0
-
getTraceId
APM trace ID for tracing the request across microservices- Since:
- Common Error 3.0.0
-
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).
-
withErrorRef
Unique reference code for support and logs correlation- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed). - Since:
- Common Error 3.0.0
-
withTraceId
APM trace ID for tracing the request across microservices- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed). - Since:
- Common Error 3.0.0
-
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() -
setErrorRef
Unique reference code for support and logs correlation- Since:
- Common Error 3.0.0
-
setTraceId
APM trace ID for tracing the request across microservices- Since:
- Common Error 3.0.0
-