Package org.kiwiproject.jaxrs.exception
Class ErrorMessage
- java.lang.Object
-
- org.kiwiproject.jaxrs.exception.ErrorMessage
-
public class ErrorMessage extends Object
An error message that kiwi uses in JAX-RS related utilities. This is effectively a replacement for the Dropwizard class of the same name.Each instance contains the HTTP status (error) code; the error message; an optional identifier to identify the specific item causing the error (e.g. a primary key); and an optional field/property name for cases when a specific field causes the error.
-
-
Field Summary
Fields Modifier and Type Field Description static StringKEY_CODEstatic StringKEY_FIELD_NAMEstatic StringKEY_ITEM_IDstatic StringKEY_MESSAGE
-
Constructor Summary
Constructors Constructor Description ErrorMessage(int code, String message)Create instance with the given HTTP status code and message.ErrorMessage(int code, String message, String fieldName)Create instance with the given HTTP status code, message, and field/property name.ErrorMessage(String message)Create instance with the given message and the default status code (500).ErrorMessage(String itemId, int code, String message, String fieldName)Create instance with the given item identifier, HTTP status code, message, and field/property name.ErrorMessage(javax.ws.rs.core.Response.Status status, String message)Create instance with the given HTTP status and message.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,Object>toMap()Convert this instance to a map.StringtoString()static ErrorMessagevalueOf(Map<String,Object> props)Build anErrorMessagefrom the given map of properties, whose keys must correspond to the property names and whose values must have the expected type.
-
-
-
Field Detail
-
KEY_CODE
public static final String KEY_CODE
- See Also:
- Constant Field Values
-
KEY_FIELD_NAME
public static final String KEY_FIELD_NAME
- See Also:
- Constant Field Values
-
KEY_ITEM_ID
public static final String KEY_ITEM_ID
- See Also:
- Constant Field Values
-
KEY_MESSAGE
public static final String KEY_MESSAGE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ErrorMessage
public ErrorMessage(String message)
Create instance with the given message and the default status code (500).- Parameters:
message- the error message
-
ErrorMessage
public ErrorMessage(javax.ws.rs.core.Response.Status status, String message)Create instance with the given HTTP status and message.- Parameters:
status- the HTTP response statusmessage- the error message
-
ErrorMessage
public ErrorMessage(int code, String message)Create instance with the given HTTP status code and message.- Parameters:
code- the HTTP status codemessage- the error message
-
ErrorMessage
public ErrorMessage(int code, String message, String fieldName)Create instance with the given HTTP status code, message, and field/property name.- Parameters:
code- the HTTP status codemessage- the error messagefieldName- the field/property name that caused this error
-
ErrorMessage
@ConstructorProperties({"itemId","code","message","fieldName"}) public ErrorMessage(String itemId, int code, String message, String fieldName)
Create instance with the given item identifier, HTTP status code, message, and field/property name.Note that only this constructor has been marked with
ConstructorPropertiesdue to an open (as of 2020-09-02) issue in Jackson Databind. See jackson-databind issue #1514.- Parameters:
itemId- the unique ID of the item that caused this errorcode- the HTTP status codemessage- the error messagefieldName- the field/property name that caused this error
-
-
Method Detail
-
toMap
public Map<String,Object> toMap()
Convert this instance to a map.- Returns:
- an unmodifiable map
- See Also:
Collections.unmodifiableMap(Map)
-
valueOf
public static ErrorMessage valueOf(Map<String,Object> props)
Build anErrorMessagefrom the given map of properties, whose keys must correspond to the property names and whose values must have the expected type.- Parameters:
props- error message properties- Returns:
- a new ErrorMessage
-
-