JSON Middleware

class smarter.lib.django.middleware.json.SmarterJsonErrorMiddleware(get_response, *args, **kwargs)[source]

Bases: SmarterMiddlewareMixin

Middleware that converts non-JSON error responses into JSON responses.

for clients requesting JSON content.

static build_error_payload(response)[source]

Build standardized JSON error payload.

Return type:

dict

client_accepts_json(request)[source]

Determine whether the client accepts JSON responses.

Return type:

bool

property formatted_class_name: str

Returns the class name formatted for logging.

Returns:

The formatted class name as a string.

Return type:

str

normalize_json_error_response(request, response)[source]

Convert non-JSON error responses into JsonResponse objects.

Return type:

HttpResponseBase

static response_is_json(response)[source]

Detect whether the response is already JSON.

Return type:

bool