Class ErrorMessage

java.lang.Object
org.kiwiproject.jaxrs.exception.ErrorMessage

public class ErrorMessage extends Object
An error message that kiwi uses in Jakarta REST 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 Details

  • Constructor Details

    • 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(jakarta.ws.rs.core.Response.Status status, String message)
      Create instance with the given HTTP status and message.
      Parameters:
      status - the HTTP response status
      message - 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 code
      message - 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 code
      message - the error message
      fieldName - 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 ConstructorProperties due 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 error
      code - the HTTP status code
      message - the error message
      fieldName - the field/property name that caused this error
  • Method Details

    • toMap

      public Map<String,Object> toMap()
      Convert this instance to a map.
      Returns:
      an unmodifiable map
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • valueOf

      public static ErrorMessage valueOf(Map<String,Object> props)
      Build an ErrorMessage from 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
    • getCode

      public int getCode()
    • getFieldName

      public String getFieldName()
    • getItemId

      public String getItemId()
    • getMessage

      public String getMessage()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object