Skip to content

Don't crash parser on empty JSON response#12

Open
reist wants to merge 1 commit into
bguban:masterfrom
seekingalpha:catch-bad-web-responses
Open

Don't crash parser on empty JSON response#12
reist wants to merge 1 commit into
bguban:masterfrom
seekingalpha:catch-bad-web-responses

Conversation

@reist

@reist reist commented Jul 23, 2024

Copy link
Copy Markdown

Warn instead

"responses" => examples.group_by { |ex| ex.response['code'] }.map do |code, variants|
responses = variants.map do |v|
parsed = parse_body(v.response)
puts "Empty response at #{v['description']}, #{route}, HTTP code #{code}" unless parsed

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

puts doesn't look like a good approach here. The better way is to pass a logger via the initializer and have a default one that will output into the console. Then this logger can be used in the code to provide output

"responses" => examples.group_by { |ex| ex.response['code'] }.transform_values do |variants|
{
"description" => variants.first["description"].capitalize,
"responses" => examples.group_by { |ex| ex.response['code'] }.map do |code, variants|

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

responses should be a hash but not an array as I remember. Are you sure that map is a proper method here?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants