Commit:    1baa02b8ddd2506a9958d2fb2761e3acf3fa66bc
Author:    Sherif Ramadan <google...@php.net>         Wed, 12 Dec 2012 12:49:10 
-0500
Parents:   07fee124ab8f8382ab6762d01d7cb35b095f4540
Branches:  master

Link:       
http://git.php.net/?p=web/php.git;a=commitdiff;h=1baa02b8ddd2506a9958d2fb2761e3acf3fa66bc

Log:
Modified the response handling from the API on master to return a useful error 
message in case of failure for the voting feature.

Changed paths:
  M  js/usernotes.js
  M  manual/vote-note.php


Diff:
diff --git a/js/usernotes.js b/js/usernotes.js
index d1d03dd..83804ea 100644
--- a/js/usernotes.js
+++ b/js/usernotes.js
@@ -23,8 +23,8 @@ $(document).ready(function() {
             }
             else {
               var responsedata = "Error :(";
-              if (data.message != null) {
-                responsedata = data.message;
+              if (data.msg != null) {
+                responsedata = data.msg;
               }
               $("#V"+id).html("<div style=\"float: left; width: 16px; height: 
16px; background-image: url(/images/notes-features.png); 
background-position:-32px 0px; margin-right: 8px; overflow: hidden;\" 
border=\"0\" alt=\"fail\" title=\"" + responsedata + "\"></div>");
             }
diff --git a/manual/vote-note.php b/manual/vote-note.php
index 74ec804..cb0a82e 100644
--- a/manual/vote-note.php
+++ b/manual/vote-note.php
@@ -36,16 +36,19 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
       );
       if (($r = posttohost($master_url, $data)) === null || strpos($r,"failed 
to open socket to") !== false) {
         $response["success"] = false;
-        $response["msg"] = "Invalid request.";
+        $response["msg"] = "Could not process your request at this time. 
Please try again later...";
       }
       else {
         $r = json_decode($r);
         if (json_last_error() == JSON_ERROR_NONE && isset($r->status) && 
$r->status && isset($r->votes)) {
           $response["success"] = true;
           $response["update"] = (int)$r->votes;
+        } elseif (json_last_error() == JSON_ERROR_NONE && isset($r-status) && 
isset($r->message) && $r->status == false) {
+          $response["success"] = false;
+          $response["msg"] = $r->message;
         } else {
           $response["success"] = false;
-          $response["msg"] = "Response unrecognized.";
+          $response["msg"] = "The server did not respond properly. Please try 
again later...";
         }
       }
     }


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to