<commit_before>import asyncio
import json
import logging

from aio_jsonrpc_20.exception import (
    InvalidRequestException,
    CustomJsonRpcException
)
from aio_jsonrpc_20.response import ResponseMaker
from aio_jsonrpc_20.utils import (
    is_valid_params,
    check_request,
    lazy_check_request
)


logger = logging.getLogger(__name__)


class RequestResolver(object):
    """This class allow to resolve a request, and build a response."""
    __slots__ = [
        'router',
        'serializer',
        'response_maker',
        'check_request'
    ]

    def __init__(
            self,
            router,
            lazy_check=False,
            error_verbose=True,
            serializer=json
    ):
        self.router = router
        self.response_maker = ResponseMaker(error_verbose)
        self.serializer = serializer

        if lazy_check:
            self.check_request = lazy_check_request
        else:
            self.check_request = check_request

    async def handle(self, str_request):
        # handle encoding
        if isinstance(str_request, bytes):
            str_request = str_request.decode("utf-8")

        # get response from unserialized request
        try:
            request = self.serializer.loads(str_request)
        except (TypeError, ValueError):
            logger.warning('Bad formatted json')
            response = self.response_maker.get_parse_error(
                data='Bad formatted json'
            )
        else:
            if request:
                try:
                    # batch request case
                    if isinstance(request, list):
                        coros = []
                        for sub_req in request:
                            coros.append(self._get_response(sub_req))
                        response = await asyncio.gather(*coros)
                        response = [elt for elt in response if elt]
                    # simple request case
                    else:
                        response = await self._get_response(request)
                # handle uncaught exception
                except Exception as e:
                    logger.warning('Unexpected error: ' + str(e))<commit_msg>Enhance JSON decode error logging<commit_after>import asyncio
import json
import logging

from aio_jsonrpc_20.exception import (
    InvalidRequestException,
    CustomJsonRpcException
)
from aio_jsonrpc_20.response import ResponseMaker
from aio_jsonrpc_20.utils import (
    is_valid_params,
    check_request,
    lazy_check_request
)


logger = logging.getLogger(__name__)


class RequestResolver(object):
    """This class allow to resolve a request, and build a response."""
    __slots__ = [
        'router',
        'serializer',
        'response_maker',
        'check_request'
    ]

    def __init__(
            self,
            router,
            lazy_check=False,
            error_verbose=True,
            serializer=json
    ):
        self.router = router
        self.response_maker = ResponseMaker(error_verbose)
        self.serializer = serializer

        if lazy_check:
            self.check_request = lazy_check_request
        else:
            self.check_request = check_request

    async def handle(self, str_request):
        # handle encoding
        if isinstance(str_request, bytes):
            str_request = str_request.decode("utf-8")

        # get response from unserialized request
        try:
            request = self.serializer.loads(str_request)
        except (TypeError, ValueError) as decode_error:
            logger.warning('JSON decode error: {}'.format(decode_error))
            response = self.response_maker.get_parse_error(
                data='Could not decode JSON request object.'
            )
        else:
            if request:
                try:
                    # batch request case
                    if isinstance(request, list):
                        coros = []
                        for sub_req in request:
                            coros.append(self._get_response(sub_req))
                        response = await asyncio.gather(*coros)
                        response = [elt for elt in response if elt]
                    # simple request case
                    else:
                        response = await self._get_response(request)
                # handle uncaught exception
                except Exception as e:
                    logger.warning('Unexpected error: ' + str(e))
{'fraction_non_alphanumeric': 0.06809555704398303, 'fraction_numerical': 0.003125697700379549, 'mean_word_length': 1.6874625074985004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2980685', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1102, 'n_words': 279}