HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/primordial/wsgi/falcontools.py
# -*- coding: utf-8 -*-

import json
from json.decoder import JSONDecodeError
import logging

import falcon


LOG = logging.getLogger(__name__)


def json_body(req: falcon.Request, *_) -> None:
    """Decode JSON request body and attach to request as `body`.

    :param req: The request to be processed
    :raises falcon.HTTPBadRequest: In the case of invalid JSON
    """
    body = req.bounded_stream.read().decode('utf-8')
    try:
        req.body = json.loads(body) if body else {}
    except JSONDecodeError as ex:
        raise falcon.HTTPBadRequest(
            code='BAD_JSON',
            description=str(ex))