External API error handling in Ruby
When making external API requests, implement proper error handling with descriptive logging to help with debugging issues.
Bad:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
JSON.parse(response.body)
end
Install this rule for wispbit
Quick Install
Run this one command to automatically install the rule:
Manual install
Copy the rule
---
include: app/controllers/**/*.rb
---
When making external API requests, implement proper error handling with descriptive logging to help with debugging issues.
Bad:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
JSON.parse(response.body)
end
```
Good:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
if response.success?
JSON.parse(response.body)
else
Rails.logger.error("API request failed: status=#{response.code}, message=#{response.message}, body=#{response.body}")
nil
end
end
```
Add the rule into your project
.wispbit/rules/ruby-external-api-handling.md
Install this rule for Coderabbit
Copy the configuration below and add it to your repository as .coderabbit.yml
in your project root.
reviews:
path_instructions:
- path: "app/controllers/**/*.rb"
instructions: |
When making external API requests, implement proper error handling with descriptive logging to help with debugging issues.
Bad:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
JSON.parse(response.body)
end
```
Good:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
if response.success?
JSON.parse(response.body)
else
Rails.logger.error("API request failed: status=#{response.code}, message=#{response.message}, body=#{response.body}")
nil
end
end
```
Install this rule for Greptile
Greptile rules can be added through the web interface. Please see this documentation for details on how to add custom rules and context.
When making external API requests, implement proper error handling with descriptive logging to help with debugging issues.
Bad:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
JSON.parse(response.body)
end
```
Good:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
if response.success?
JSON.parse(response.body)
else
Rails.logger.error("API request failed: status=#{response.code}, message=#{response.message}, body=#{response.body}")
nil
end
end
```
File Path Patterns:
Install this rule for GitHub Copilot
Copilot instructions can be added through the interface. See the documentation for details on how to create coding guidelines.
When making external API requests, implement proper error handling with descriptive logging to help with debugging issues.
Bad:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
JSON.parse(response.body)
end
```
Good:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
if response.success?
JSON.parse(response.body)
else
Rails.logger.error("API request failed: status=#{response.code}, message=#{response.message}, body=#{response.body}")
nil
end
end
```
File Path Patterns:
Install this rule for Graphite Diamond
Diamond custom rules can be added through the interface. See the documentation for details on how to create custom rules.
When making external API requests, implement proper error handling with descriptive logging to help with debugging issues.
Bad:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
JSON.parse(response.body)
end
```
Good:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
if response.success?
JSON.parse(response.body)
else
Rails.logger.error("API request failed: status=#{response.code}, message=#{response.message}, body=#{response.body}")
nil
end
end
```
File Path Patterns:
Use with Cline
Copy the rule below and ask Cline to review your code using this rule
When making external API requests, implement proper error handling with descriptive logging to help with debugging issues.
Bad:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
JSON.parse(response.body)
end
```
Good:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
if response.success?
JSON.parse(response.body)
else
Rails.logger.error("API request failed: status=#{response.code}, message=#{response.message}, body=#{response.body}")
nil
end
end
```
Use with OpenAI Codex
Copy the rule below and ask OpenAI Codex to review your code using this rule
When making external API requests, implement proper error handling with descriptive logging to help with debugging issues.
Bad:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
JSON.parse(response.body)
end
```
Good:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
if response.success?
JSON.parse(response.body)
else
Rails.logger.error("API request failed: status=#{response.code}, message=#{response.message}, body=#{response.body}")
nil
end
end
```
Use with Cursor
Copy the rule below and ask Cursor to review your code using this rule
When making external API requests, implement proper error handling with descriptive logging to help with debugging issues.
Bad:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
JSON.parse(response.body)
end
```
Good:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
if response.success?
JSON.parse(response.body)
else
Rails.logger.error("API request failed: status=#{response.code}, message=#{response.message}, body=#{response.body}")
nil
end
end
```
Use with Claude Code
Copy the rule below and ask Claude Code to review your code using this rule
When making external API requests, implement proper error handling with descriptive logging to help with debugging issues.
Bad:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
JSON.parse(response.body)
end
```
Good:
```ruby
def fetch_external_data
response = HTTParty.get("https://api.example.com/data")
if response.success?
JSON.parse(response.body)
else
Rails.logger.error("API request failed: status=#{response.code}, message=#{response.message}, body=#{response.body}")
nil
end
end
```