def error_respond(self, error):
        """Create an error response to this request.

        When processing the request produces an error condition this method can be used to
        create the error response object.

        :param error: Specifies what error occurred.
        :type error: str or Exception
        :returns: An error response object that can be serialized and sent to the client.
        :rtype: :py:class:`JSONRPCErrorResponse`
        """
        if self.unique_id is None:
            return None

        response = JSONRPCErrorResponse()
        response.unique_id = None if self.one_way else self.unique_id

        code, msg, data = _get_code_message_and_data(error)

        response.error = msg
        response._jsonrpc_error_code = code
        if data:
            response.data = data
        return response