Seldaek/monolog · error · RuntimeException

Telegram API error. Description: Unexpected non-JSON respons

Error message

Telegram API error. Description: Unexpected non-JSON response

What it means

Error "Telegram API error. Description: Unexpected non-JSON response" thrown in Seldaek/monolog.

Source

Thrown at src/Monolog/Handler/TelegramBotHandler.php:317

        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));

        $this->validateApiResponse(Curl\Util::execute($ch));
    }

    /**
     * @param  string|bool      $rawResult Raw response body from the Telegram API call
     * @throws RuntimeException When the response is missing, non-JSON, or signals failure
     */
    protected function validateApiResponse(string|bool $rawResult): void
    {
        if (!\is_string($rawResult)) {
            throw new RuntimeException('Telegram API error. Description: No response');
        }

        $result = json_decode($rawResult, true);

        if (!\is_array($result)) {
            throw new RuntimeException('Telegram API error. Description: Unexpected non-JSON response');
        }
        if (($result['ok'] ?? null) !== true) {
            throw new RuntimeException('Telegram API error. Description: ' . ($result['description'] ?? 'Unknown error'));
        }
    }

    /**
     * Handle a message that is too long: truncates or splits into several
     * @return string[]
     */
    private function handleMessageLength(string $message): array
    {
        $truncatedMarker = ' (…truncated)';
        if (!$this->splitLongMessages && \strlen($message) > self::MAX_MESSAGE_LENGTH) {
            return [Utils::substr($message, 0, self::MAX_MESSAGE_LENGTH - \strlen($truncatedMarker)) . $truncatedMarker];
        }

        return str_split($message, self::MAX_MESSAGE_LENGTH);

View on GitHub (pinned to 57eb102834)

When it happens

Trigger: Thrown at src/Monolog/Handler/TelegramBotHandler.php:317 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Seldaek/monolog@57eb102834 (2026-08-17). Data as JSON: /api/errors/2dad20fad0605b87. Report an issue: GitHub.