SmarterJournaledJsonErrorResponse

class smarter.lib.journal.http.SmarterJournaledJsonErrorResponse(request, e, encoder=<class 'smarter.lib.json.SmarterJSONEncoder'>, safe=True, thing=None, command=None, json_dumps_params=None, stack_trace='No stack trace available.', description=None, status=500, include_stack_trace=True, **kwargs)[source]

Bases: SmarterJournaledJsonResponse

Enhanced HTTP error response for Smarter CLI commands.

This class serializes error information in a structured JSON format consumable by the Smarter CLI, allowing for consistent error formatting and display in the user console. It is the common error response for all CLI commands.

A server error (5xx) is logged at ERROR, with its stack trace. A client error (4xx), e.g. an invalid api key or a rejected manifest, is expected, so it is logged at WARNING, without the stack trace.

Parameters:
  • request (HttpRequest) – The original Django request object.

  • e (Exception | None) – The Python exception object that was raised.

  • encoder (type[JSONEncoder]) – JSON encoder class. Defaults to smarter.lib.json.SmarterJSONEncoder.

  • safe (bool) – Controls if only dict objects may be serialized. Defaults to True.

  • thing (SmarterJournalThings | str | None) – The resource or entity being operated on (noun).

  • command (SmarterJournalCliCommands | None) – The CLI command executed on the resource.

  • json_dumps_params (dict[str, Any] | None) – Additional kwargs for json.dumps().

  • stack_trace (str) – The stack trace for the exception.

  • description (str | None) – Human-readable error description. Defaults to the exception’s message attribute, if it has one.

  • status (int) – The HTTP status code. Defaults to 500.

  • include_stack_trace (bool) – Whether the response includes stack_trace. Defaults to True. Responses that a browser may receive, e.g. those of the Smarter Chat apis, pass False: the stack trace of a server error is still logged, but is never sent to the client.

  • kwargs – Additional keyword arguments passed to the parent class.

Example error response JSON, a SAMJournalApiErrorResponse beside the envelope:

{
    "error": {
        "errorClass": "SAMBrokerErrorNotFound",
        "stacktrace": "...",
        "description": "Guardrail example not found",
        "status": 404,
        "args": "url=https://...",
        "cause": "Python Exception",
        "context": "thing=Guardrail, command=describe",
        "thing": "Guardrail",
        "command": "describe"
    },
    "api": "smarter.sh/v1",
    "metadata": {"command": "describe", "thing": "Guardrail", "key": "4f1c...e9a2"}
}
__init__(request, e, encoder=<class 'smarter.lib.json.SmarterJSONEncoder'>, safe=True, thing=None, command=None, json_dumps_params=None, stack_trace='No stack trace available.', description=None, status=500, include_stack_trace=True, **kwargs)[source]

Note: this needs to exist; something in the Python MRO requires it, even if it does nothing.

If you remove this, you will get a mysterious error about something downstream expecting exactly one object.