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




commit 7926b5ebcfcaab5b6e7c74135d146ac451cf2626
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 c42121f77..c0821d5ba 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 89be457a0..cf3c87f3d 100644
--- a/src/json/json.cs
+++ b/src/json/json.cs
@@ -567,6 +567,7 @@ public class Json
                }
                authToken = json_response["token"];
 //             LogB.Debug("authToken: " + authToken + "\n");
+               LogB.Debug("Authenticated Correctly!\n");
                return true;
        }
 
@@ -619,7 +620,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);
@@ -635,7 +653,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);
@@ -651,7 +686,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]