Class ErrorEnvelope

java.lang.Object
is.codion.framework.json.db.ErrorEnvelope

public final class ErrorEnvelope extends Object
The body of a JSON error response, the wire form of a server side exception.

Carries a closed ErrorKind, a message, a correlation id linking the response to a server log entry, and a kind specific detail node for the kinds whose exception cannot be reconstructed from a message alone.

Neither a stack trace nor a cause chain is ever carried, in either direction. A client reconstructing an exception from an envelope maps the kind() to a known constructor; nothing on the wire names a class.

 {
   "kind" : "CONFLICT_REFERENTIAL",
   "message" : "Delete failed, the record is referenced by another record",
   "correlationId" : "b1f4c8e2-3a1d-4f0b-9c5e-7d2a6f8b1c3e",
   "detail" : { "operation" : "DELETE" }
 }
See Also:
  • Field Details

  • Constructor Details

    • ErrorEnvelope

      public ErrorEnvelope(String kind, String message, String correlationId, @Nullable com.fasterxml.jackson.databind.JsonNode detail)
      Parameters:
      kind - the ErrorKind name, a string rather than the enum so an unknown kind does not fail to parse
      message - the error message
      correlationId - identifies the server log entry describing this error
      detail - kind specific detail, null if the kind carries none
  • Method Details

    • kind

      public String kind()
      Returns:
      the ErrorKind name, see errorKind()
    • message

      public String message()
      Returns:
      the error message
    • correlationId

      public String correlationId()
      Returns:
      the id identifying the server log entry describing this error
    • detail

      public @Nullable com.fasterxml.jackson.databind.JsonNode detail()
      Returns:
      the kind specific detail, or null if the kind carries none
    • errorKind

      public Optional<ErrorKind> errorKind()
      Returns:
      the ErrorKind, an empty Optional in case this envelope carries a kind unknown here, which a client older than the server encounters
    • toString

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

      public String toJson() throws com.fasterxml.jackson.core.JsonProcessingException
      Returns:
      this envelope as a JSON string
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - in case of an error
    • fromJson

      public static ErrorEnvelope fromJson(byte[] json) throws IOException
      Parameters:
      json - the JSON to parse
      Returns:
      the ErrorEnvelope the given JSON represents
      Throws:
      IOException - in case the given JSON is not an error envelope