petals-infra / health.petals.dev

🏥 Health monitor for a Petals swarm
https://health.petals.dev
32 stars 26 forks source link

State response endpoint fails when parsing #16

Closed filopedraz closed 12 months ago

filopedraz commented 12 months ago

Description

Getting error when fetching https://health.petals.dev/api/v1/state endpoint.

There was a problem fetching the data: SyntaxError: JSON.parse: unexpected character at line 362 column 67 of the JSON data

Here is a simple example using the endpoint.


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Fetch and Display JSON</title>
</head>
<body>

<h2>JSON Data from Endpoint:</h2>
<pre id="jsonData"></pre>

<script>
    async function fetchDataFromEndpoint() {
        try {
            // Define the endpoint URL (replace with your own URL)
            let url = 'https://health.petals.dev/api/v1/state';

            // Fetch data from the endpoint
            let response = await fetch(url);

            // Check if the request was successful
            if (!response.ok) {
                throw new Error(`HTTP error! Status: ${response.status}`);
            }

            // Convert the response to JSON
            let data = await response.json();

            // Display the fetched JSON in the <pre> tag
            document.getElementById('jsonData').textContent = JSON.stringify(data, null, 2);

        } catch (error) {
            console.error("There was a problem fetching the data:", error);
            document.getElementById('jsonData').textContent = 'Failed to fetch data.';
        }
    }

    // Fetch data when the page loads
    window.onload = fetchDataFromEndpoint;

</script>

</body>
</html>

Inspecting the response I noticed that it returns an Infinity value.

"next_pings": {
                "12D3KooWPM6dPXzbBVJswqSTNkWZwZ6LxQUgwuTGnzmhjy5ymi1j": 0.33408880466928004,
                "Qmc3JUuzGjApZk6UPF1XBQttdjv1efKbkSY1zpFLZj98Se": Infinity,
borzunov commented 12 months ago

Thanks for reporting!

Just fixed it, see https://github.com/petals-infra/health.petals.dev/pull/17#issuecomment-1730539211