Skip to content

Unhandled status code causes runtime error #491

@adsteel

Description

@adsteel

Version info

  • intercom-ruby version: 3.8
  • Ruby version: 2.6.2

Expected behavior

When an unexpected response code is returned, an intentional error is always raised.

Actual behavior

When an unexpected response code is returned, a NoMethodError: undefined method '[]' for nil:NilClass is raised.

Steps to reproduce

Because this is a runtime error I'm not sure what condition is causing this, but we can see the issue in the code. See error trace in the logs section below.

  1. Given a parsed_body of nil (the default state): https://github.com/intercom/intercom-ruby/blob/master/lib/intercom/request.rb#L106
  2. We attempt to raise an error on nil? here: https://github.com/intercom/intercom-ruby/blob/master/lib/intercom/request.rb#L113
  3. But there is no fallback error raised if the status code is unexpected: https://github.com/intercom/intercom-ruby/blob/master/lib/intercom/request.rb#L146
  4. So we raise a NoMethodError here: https://github.com/intercom/intercom-ruby/blob/master/lib/intercom/request.rb#L114

Logs

Error trace from our error reporter.

/gems/intercom-3.8.0/lib/intercom/request.rb:114 in parse_body
/gems/intercom-3.8.0/lib/intercom/request.rb:77 in block in execute
vendor/ruby-2.6.2/lib/ruby/2.6.0/net/http.rb:920 in start

918:
        begin
919:
          do_start
920:
          return yield(self)
921:
        ensure
922:
          do_finish
/gems/intercom-3.8.0/lib/intercom/request.rb:72 in execute
/gems/intercom-3.8.0/lib/intercom/client.rb:140 in execute_request
/gems/intercom-3.8.0/lib/intercom/client.rb:115 in post
/gems/intercom-3.8.0/lib/intercom/api_operations/save.rb:27 in save
/gems/intercom-3.8.0/lib/intercom/api_operations/save.rb:19 in create

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions