AO3-7414 Display error messages for multi-URL import#5792
AO3-7414 Display error messages for multi-URL import#5792lynnhaotran wants to merge 4 commits intootwcode:masterfrom
Conversation
| # collect the errors neatly, matching each error to the failed url | ||
| unless failed_urls.empty? | ||
| error_msgs = 0.upto(failed_urls.length).map { |index| "<dt>#{failed_urls[index]}</dt><dd>#{errors[index]}</dd>" }.join("\n") | ||
| error_msgs = (0...failed_urls.length).map do |index| |
There was a problem hiding this comment.
0.upto(failed_urls.length) includes failed_urls.length, so failed_url[index] was returning nil in the last iteration. Using ... to make the range exclusive, but also happy to change it to 0.upto(failed_urls.length - 1) if that reads better.
| "<li>failedurl2 first error</li>" \ | ||
| "</ul>" \ | ||
| "</dl>" | ||
| ) |
There was a problem hiding this comment.
Sorry this is a bit ugly! I wanted to test (1) that the render actually succeeded instead of getting a 500 error and (2) the formatting changes look as expected. Let me know if any changes are preferred here.
| error_msgs = 0.upto(failed_urls.length).map { |index| "<dt>#{failed_urls[index]}</dt><dd>#{errors[index]}</dd>" }.join("\n") | ||
| error_msgs = (0...failed_urls.length).map do |index| | ||
| # each failed url may have multiple errors, so show them in a bulleted list underneath the url | ||
| errors_per_url = errors[index].map { |error| "<li>#{error}</li>" } |
There was a problem hiding this comment.
I'm assuming by this point any content in the error messages (from validation, etc.) have been properly sanitized by StoryParser already? Or is that something I should be concerned about here?
Pull Request Checklist
as the first thing in your pull request title (e.g.
AO3-1234 Fix thing)until they are reviewed and merged before creating new pull requests.
Issue
https://otwarchive.atlassian.net/browse/AO3-7414
Purpose
This PR fixes an issue on the import page where if any URL in the list of URLs has an error, clicking 'Import' would return a 500. Now a red pop-up will appear indicating the errors that occurred for each URL that was imported. Some formatting changes were made as well so that an array of errors for a single URL is formatted as a list, similar to
ValidationHelper.error_messages_formatted.Before: 500
After (all URLs had errors):

After (some URLs had errors):

After (a URL doesn't have corresponding error messages):

Credit
lynn (she/her)