Show comment posting errors (#12184)

This commit is contained in:
Josh Puetz 2021-01-08 14:29:01 -06:00 committed by GitHub
parent e7f9735354
commit 8c5b7bacb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View file

@ -260,11 +260,16 @@ function handleCommentSubmit(event) {
activateRunkitTags();
})
} else {
form.classList.remove('submitting');
var responseStatus = response.status;
response.json().then(function parseError(errorReponse) {
form.classList.remove('submitting');
showRateLimitModal('made a comment', 'making another comment')
return false;
if (responseStatus === 429) {
showRateLimitModal('made a comment', 'making another comment')
} else {
showUserAlertModal('Error posting comment', 'Your comment could not be posted due to an error: ' + errorReponse.error, 'OK')
}
});
return false;
}
return false;
});

View file

@ -64,6 +64,24 @@ RSpec.describe "Creating Comment", type: :system, js: true do
end
end
context "when there is an error posting a comment" do
let(:unconfigured_twitter_comment) { "{% twitter 733111952256335874 %}" }
before do
stub_request(:post, "https://api.twitter.com/oauth2/token")
.to_return(status: 400, body: '{"errors":[{"code":215,"message":"Bad Authentication data."}]}', headers: {})
end
it "displays a error modal" do
visit article.path.to_s
wait_for_javascript
fill_in "text-area", with: unconfigured_twitter_comment
click_button("Submit")
expect(page).to have_text("Error posting comment")
end
end
context "with Runkit tags" do
before do
visit article.path.to_s