From 8956571d58cef133dc4674935d506d50cd89ba38 Mon Sep 17 00:00:00 2001
From: Anton Sarukhanov <code@ant.sr>
Date: Wed, 2 Nov 2016 01:46:35 -0400
Subject: [PATCH] Contact form error handling

---
 theme/static/js/script.js | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/theme/static/js/script.js b/theme/static/js/script.js
index 2722547..652adf5 100644
--- a/theme/static/js/script.js
+++ b/theme/static/js/script.js
@@ -25,8 +25,20 @@
             url: $(selector).attr("action"),
             data: $(selector).serialize(),
             success: function(response) {
-                $(selector + " :input").prop("disabled", true);
-                $(selector).prepend(response);
+                $(selector).html(response);
+            },
+            statusCode: {
+                429: function() {
+                    if (jqXHR.getResponseHeader("Retry-After")) {
+                        alert("Too many requests from your network. Please try again in "
+                            + jqXHR.getResponseHeader("Retry-After") + " seconds.");
+                    } else {
+                        alert("Too many requests from your network. Please try again later.");
+                    }
+                }
+            },
+            error: function(jqXHR, error_type, e) {
+                alert("Sorry, an error occurred. Please try again, or email me.");
             }
         });
         return false;
-- 
GitLab