Skip to content

Commit

Permalink
Ignore incorrect requests if they are passed from start_requests
Browse files Browse the repository at this point in the history
  • Loading branch information
oltarasenko committed Oct 16, 2020
1 parent 8c8e3f8 commit db15123
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/crawly/manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,17 @@ defmodule Crawly.Manager do
# Store start urls
Enum.each(
Keyword.get(init, :start_requests, []),
fn request ->
Crawly.RequestsStorage.store(spider_name, request)
fn
%Crawly.Request{} = request ->
Crawly.RequestsStorage.store(spider_name, request)

request ->
# We should not attempt to store something which is not a request
Logger.error(
"#{inspect(request)} does not seem to be a request. Ignoring."
)

:ignore
end
)

Expand Down
5 changes: 4 additions & 1 deletion test/manager_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ defmodule Manager.StartRequestsTestSpider do

def init() do
[
start_requests: [Crawly.Request.new("https://www.example.com/blog.html")]
start_requests: [
Crawly.Request.new("https://www.example.com/blog.html"),
"Incorrect request"
]
]
end

Expand Down

0 comments on commit db15123

Please sign in to comment.