Skip to content

nil response from RestClient causes 'undefined method `code' for nil:NilClass' #13

@deepanshumarwah

Description

@deepanshumarwah

res = RestClient.post( uri, body, headers)
res
rescue => e
c = e.response.code.to_i
if c == 429 || c == 500 || c==503
if retries < @max_retries
retries += 1
sleep(@retry_sleep_period)
retry
end
end
raise e
end
end

res can be nil here, leading to a scenario where the following is logged from the logstash-output-azure_loganalytics plugin when Azure::Loganalytics::Datacollectorapi::Client.is_success(res) is called and is_success attempts to evaluate res.code
from logstash:

[ERROR][logstash.outputs.azureloganalytics][pipeline-common][pipeline_common_output_azure_log_analytics_ingest] Exception occured in posting to DataCollector API as log type ExampleLogType: 'undefined method `code' for nil:NilClass', data=>[{"original_timestamp":"2021-04-15T10:36:21.315Z","event_uuid":"ede25ed2-0d3e-4898-8c5d-3...

There appears to be a related issue logged at rest-client/rest-client#655

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