Protocol for converting Apical errors to JSON-compatible maps.
This protocol provides a consistent way to convert Apical exceptions to maps that can be easily serialized to JSON for API error responses.
Example
error = %Apical.Exceptions.ParameterError{
operation_id: "getUser",
in: :path,
reason: "required parameter `id` not present"
}
json_map = Apical.ToJson.to_json(error)
# => %{
# error: "parameter_error",
# status: 400,
# operation_id: "getUser",
# location: "path",
# message: "Parameter Error in operation getUser (in path): ..."
# }
Jason.encode!(json_map)
# => "{"error":"parameter_error","status":400,...}"
Summary
Functions
Converts an Apical exception to a JSON-compatible map.
Types
@type t() :: term()
All the types that implement this protocol.
Functions
Converts an Apical exception to a JSON-compatible map.
Returns a map with at minimum:
:error- A string identifier for the error type:status- The HTTP status code:message- A human-readable error message
Additional fields may be included depending on the error type.