Skip to content

Commit

Permalink
Adds TYPICAL_ERRORS' array and adds back safe navigation operator &…
Browse files Browse the repository at this point in the history
….` to `results = response&.`:

- Prevents:  'NameError:
       uninitialized constant ArticleImporter::TYPICAL_ERRORS' when `ApiErrorHandling` sets the error level
- Prevents: 'NoMethodError:
       undefined method `dig' for nil:NilClass
             results = response.dig('query', 'pages')
                               ^^^^' when response is nil ( for example when methods that call `import_articles_by_title` are mocked, the api_post response becomes `nil`)
  • Loading branch information
empty-codes committed Feb 24, 2025
1 parent fcb5eaa commit 87da8e5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/importers/article_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def import_articles_by_title(titles)
titles: some_article_titles.join('|')
}
response = api_post(@wiki.api_url, params)
results = response.dig('query', 'pages')
results = response&.dig('query', 'pages')
next if results.blank?
import_articles_from_title_query(results)
end
Expand Down Expand Up @@ -102,4 +102,8 @@ def too_many_requests?(e)
return false unless e.instance_of?(MediawikiApi::HttpError)
e.status == 429
end

TYPICAL_ERRORS = [Net::ReadTimeout,
MediawikiApi::HttpError,
MediawikiApi::ApiError].freeze
end

0 comments on commit 87da8e5

Please sign in to comment.