sahilpaudel
How to handle error inside Enum.each
I am trying to read a CSV file that has single column URL with multiple corresponding URLs for the same.
Library: nimble_csv
I have attached gist file url of the code.
I am able to read the urls from the file.
The problem I am facing is while I am iterating urls using Enum.each so I wanted to know that if one iteration fails inside Enum.each function, how can I handle that as like for this url the processing failed or for 2 iteration I want to send response that this two url is not processed.
Most Liked
ryanzidago
Inside the Enum.each/2 function, you could insert a case statement?
Enum.each(urls, fn url ->
case try_parse_url(url) do
url -> url
{:error, unprocessed_url -> append_to_the_list_of_unprocessed_urls(unprocessed_url)
end)
where the function try_parse_url/1 do some kind of pattern matching against a binary string to check if it is a proper URL or not and if not, then the unprocessed URL is appended to some kind of list.
What do you think?







