Skip to content

AO3-7414 Display error messages for multi-URL import#5792

Open
lynnhaotran wants to merge 4 commits intootwcode:masterfrom
lynnhaotran:AO3-7414/fix_multi_import_500
Open

AO3-7414 Display error messages for multi-URL import#5792
lynnhaotran wants to merge 4 commits intootwcode:masterfrom
lynnhaotran:AO3-7414/fix_multi_import_500

Conversation

@lynnhaotran
Copy link
Copy Markdown

Pull Request Checklist

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):
Screenshot 2026-05-07 at 4 11 47 PM

After (some URLs had errors):
Screenshot 2026-05-07 at 2 05 04 PM

After (a URL doesn't have corresponding error messages):
Screenshot 2026-05-07 at 2 02 11 PM

Credit

lynn (she/her)

# 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|
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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>"
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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>" }
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant