Skip to content

504 Gateway Time-out leads to serde error #772

Closed

Description

@LilyFirefly

I'm using Octocrab to interact with the GitHub API in my lilyenv tool. I have recently noticed (LilyFirefly/lilyenv#13) that sometimes a serde error is returned from this code:

pub async fn cpython_releases() -> Result<Vec<Python>, Error> {
    let octocrab = octocrab::instance();
    let releases = octocrab
        .repos("indygreg", "python-build-standalone")
        .releases()
        .list()
        .send()
        .await?;
    ...
}

By cloning Octocrab and editing the map_github_error function in src/lib.rs I was able to see the response that was causing this error:

Response {
    status: 504,
    version: HTTP/1.1,
    headers: {
        "content-length": "92",
        "cache-control": "no-cache",
        "content-type": "text/html",
        "date": "Wed, 07 May 2025 23:34:40 GMT",
        "x-ratelimit-limit": "60",
        "x-ratelimit-remaining": "55",
        "x-ratelimit-reset": "1746664469",
        "x-ratelimit-resource": "core",
        "x-ratelimit-used": "5",
        "x-github-request-id": "C216:1D5A9C:83F6E5:A3B9AA:681BEE10"
    },
    body: BoxBody
}

where body is:

<html><body><h1>504 Gateway Time-out</h1>
The server didn't respond in time.
</body></html>

Clearly this isn't valid json, so serde_json::from_slice fails to decode the body, leading to a serde error bubbling up to my code to handle, which I found impossible to debug without editing Octocrab.

Activity

  1. XAMPPRocky commented on May 8, 2025

    @XAMPPRocky
    Owner

    Thank you for your issue! Yeah, we should catch and handle that, it's annoying how it's the one place not returning JSON.

  2. majiayu000 commented on Mar 28, 2026

    @majiayu000

    Hi, I've been looking into this and traced the root cause.

    Proposed approach: In the response handling path (map_github_error in src/lib.rs), check the Content-Type header before attempting JSON deserialization. If Content-Type is not application/json (e.g., text/html for 504 gateway timeouts), return a proper GitHubError with the HTTP status code and raw body text instead of attempting serde_json::from_slice. Follow the pattern established by PR #503 which fixed similar 204-related serde errors.

    I'll open a draft PR shortly. Happy to adjust based on your preference.

  3. shepmaster commented on Jul 16, 2026

    @shepmaster
    Contributor

    This also happens for 503's:

    Jul 16 23:14:08 play-2.infra.rust-lang.org ui[1822952]: 2026-07-16T23:14:08.769312Z ERROR request{method=GET uri=/meta/gist/ed65939ce7cd0dc13c97b6a8531883a2 request_id=496974e6-6ddb-4c0c-979a-54da7e0c5cc0}: octocrab: failed with status 503 Service Unavailable
    Jul 16 23:14:08 play-2.infra.rust-lang.org ui[1822952]: 2026-07-16T23:14:08.821683Z ERROR request{method=GET uri=/meta/gist/ed65939ce7cd0dc13c97b6a8531883a2 request_id=496974e6-6ddb-4c0c-979a-54da7e0c5cc0}: ui::server_axum: Returning an error to the client error="Gist loading failed: Serde Error: expected value at line 1 column 1"
    

    At the very least, I'd love it if the 50x error was included in the error message, to help narrow down places to look when this happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions