This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new f675a90  Add a common response handler
f675a90 is described below

commit f675a907ccbd21b5a2d15030180ddd3f6f995d58
Author: Sebb <[email protected]>
AuthorDate: Sat Dec 16 18:02:12 2017 +0000

    Add a common response handler
---
 www/roster/views/app.js.rb   |  2 ++
 www/roster/views/utils.js.rb | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/www/roster/views/app.js.rb b/www/roster/views/app.js.rb
index 3a33024..47950dd 100644
--- a/www/roster/views/app.js.rb
+++ b/www/roster/views/app.js.rb
@@ -37,3 +37,5 @@ require_relative 'confirm'
 
 require_relative 'group'
 
+require_relative 'utils'
+
diff --git a/www/roster/views/utils.js.rb b/www/roster/views/utils.js.rb
new file mode 100644
index 0000000..e287aa7
--- /dev/null
+++ b/www/roster/views/utils.js.rb
@@ -0,0 +1,26 @@
+class Utils
+  # Common processing to handle a response
+  # called from e.g. fetch($options.add_action, args).then {|response| ...
+  def self.handle_response(response)
+    content_type = response.headers.get('content-type') || ''
+    isJson = content_type.include? 'json'
+    if response.status == 200 and isJson
+      response.json().then do |json|
+        Vue.emit :update, json
+      end
+    else
+      footer = 'See server log for full details'
+      if isJson
+        response.json().then do |json|
+          # Pick out the exception
+          message = json['exception'] || ''
+          alert "#{response.status} 
#{response.statusText}\n#{message}\n#{footer}"
+        end
+      else # not JSON
+        response.text() do |text|
+          alert "#{response.status} #{response.statusText}\n#{text}\n#{footer}"
+        end
+      end
+    end
+  end
+end

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to