[chronojump/networks_v3.1] Meanwhile connection issues & normal error code are treaten in the same way, avoid false errors when



commit 076a3e5edd20233686c61c2e406c2cb523d6f6a0
Author: Leninux <arnau lenin sobtec cat>
Date:   Thu Aug 5 21:38:22 2021 +0200

    Meanwhile connection issues & normal error code are treaten in the same way, avoid false errors when an 
rfid is not found.
    Added more information on response error in order to debug easyly

 src/json/compujump.cs |  4 +++-
 src/json/json.cs      | 58 ++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 58 insertions(+), 4 deletions(-)
---
diff --git a/src/json/compujump.cs b/src/json/compujump.cs
index b076f6651..f1b6fc1eb 100644
--- a/src/json/compujump.cs
+++ b/src/json/compujump.cs
@@ -70,8 +70,10 @@ public class JsonCompujump : Json
                dataStream.Close ();
                
                HttpWebResponse response;
-               if(! getHttpWebResponse (request, out response, "Cannot get person by RFID."))
+               if(! getHttpWebResponse (request, out response, "Cannot get person by RFID.")) {
+                       connected = true;
                        return person;
+               }
 
                string responseFromServer;
                using (var sr = new StreamReader(response.GetResponseStream()))
diff --git a/src/json/json.cs b/src/json/json.cs
index 2b0b5d070..d1187ac48 100644
--- a/src/json/json.cs
+++ b/src/json/json.cs
@@ -566,6 +566,7 @@ public class Json
                }
                authToken = json_response["token"];
 //             LogB.Debug("authToken: " + authToken + "\n");
+               LogB.Debug("Authenticated Correctly!\n");
                return true;
        }
 
@@ -618,7 +619,24 @@ public class Json
 
                try {
                        dataStream = req.GetRequestStream ();
-               } catch {
+
+               } catch (WebException ex) {
+                       LogB.Warning("getHttpWebResponse error status code: "+ex.Status);
+                       if(ex.Status == WebExceptionStatus.ProtocolError) {
+                               string responseFromServer;
+                               using (var sr = new StreamReader(ex.Response.GetResponseStream())) {
+                                       responseFromServer = sr.ReadToEnd();
+                               }
+                               LogB.Warning("getHttpWebResponse error status code: "+ex.Status);
+                               LogB.Warning(responseFromServer);
+                               this.ResultMessage = errMessage + "\n" + responseFromServer;
+                       } else {
+                               this.ResultMessage = errMessage;
+                       }
+                       return false;
+
+               } catch (Exception ex) {
+                       LogB.Error(string.Format("Exception {0}", ex));
                        this.ResultMessage = errMessage + "\n" +
                                string.Format(Catalog.GetString("You are not connected to the Internet\nor 
{0} server is down."),
                                serverUrl);
@@ -634,7 +652,24 @@ public class Json
 
                try {
                        response = req.GetResponse ();
-               } catch {
+
+               } catch (WebException ex) {
+                       LogB.Warning("getHttpWebResponse error status code: "+ex.Status);
+                       if(ex.Status == WebExceptionStatus.ProtocolError) {
+                               string responseFromServer;
+                               using (var sr = new StreamReader(ex.Response.GetResponseStream())) {
+                                       responseFromServer = sr.ReadToEnd();
+                               }
+                               LogB.Warning("getHttpWebResponse error status code: "+ex.Status);
+                               LogB.Warning(responseFromServer);
+                               this.ResultMessage = errMessage + "\n" + responseFromServer;
+                       } else {
+                               this.ResultMessage = errMessage;
+                       }
+                       return false;
+
+               } catch (Exception ex) {
+                       LogB.Error(string.Format("Exception {0}", ex));
                        this.ResultMessage = errMessage + "\n" +
                                string.Format(Catalog.GetString("You are not connected to the Internet\nor 
{0} server is down."),
                                serverUrl);
@@ -650,7 +685,24 @@ public class Json
 
                try {
                        response = (HttpWebResponse) req.GetResponse ();
-               } catch {
+
+               } catch (WebException ex) {
+                       LogB.Warning("getHttpWebResponse error status code: "+ex.Status);
+                       if(ex.Status == WebExceptionStatus.ProtocolError) {
+                               string responseFromServer;
+                               using (var sr = new StreamReader(ex.Response.GetResponseStream())) {
+                                       responseFromServer = sr.ReadToEnd();
+                               }
+                               LogB.Warning("getHttpWebResponse error status code: "+ex.Status);
+                               LogB.Warning(responseFromServer);
+                               this.ResultMessage = errMessage + "\n" + responseFromServer;
+                       } else {
+                               this.ResultMessage = errMessage;
+                       }
+                       return false;
+
+               } catch (Exception ex) {
+                       LogB.Error(string.Format("Exception {0}", ex));
                        this.ResultMessage = errMessage + "\n" +
                                string.Format(Catalog.GetString("You are not connected to the Internet\nor 
{0} server is down."),
                                serverUrl);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]