Skip to content

[BUG]: GitHub sometimes returns " " or illegal characters in body in error response #1777

@Lokideos

Description

@Lokideos

What happened?

I noticed that sometimes during an error response GitHub returns " " or <illegal character like 'a'>{}, which leads to Json::ParseError errors.
I've prepared a small PR with a fix. Let me know if it works for you.

Versions

octokit 7.0; rails 7.1.3, ruby 3.2

Relevant log output

JSON::ParserError
Empty input (after ) at line 1, column 1 [parse.c:1062] (JSON::ParserError)
Breadcrumbs (lower - closer to exception):

# 1 relevant - octokit/error.rb 
def data
  @data ||=
    if (body = @response[:body]) && !body.empty?
      if body.is_a?(String) &&
         @response[:response_headers] &&
         @response[:response_headers][:content_type] =~ /json/

        Sawyer::Agent.serializer.decode(body)
      else
        body
      end
    end
end

#2 relevant - multi_json/adapter.rb 
def load(string, options = {})
  string = string.read if string.respond_to?(:read)
  fail self::ParseError if blank?(string)
  instance.load(string, cached_load_options(options))
end

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageThis is being looked at and prioritizedType: BugSomething isn't working as documented

    Type

    No type

    Projects

    Status

    🆕 Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions