From ab6edd57158574df80fe33138e99a317c64a0861 Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Sun, 12 Mar 2023 08:43:03 -0400 Subject: Better error reporting for reactions --- haunt/static/js/comment-reaction.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/haunt/static/js/comment-reaction.js b/haunt/static/js/comment-reaction.js index 844f604..bae9fed 100644 --- a/haunt/static/js/comment-reaction.js +++ b/haunt/static/js/comment-reaction.js @@ -34,9 +34,16 @@ function postReaction(reaction) { xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xhr.onload = function(data) { - if (xhr.status != 200) { - alert("Failed to react."); - } else { + switch (xhr.status) { + case 200: + break; + case 429: + alert("Failed -- you can react at most once an hour."); + break; + default: + let resp = JSON.parse(xhr.response); + alert("Failed -- " + resp.error); + break; } } xhr.onerror = function(error) { -- cgit v1.3