Explorar o código

Catch deserialization exception in AbstractClient

- Catch exceptions thrown from deserialization in AbstractClient
Alexey Edelev %!s(int64=5) %!d(string=hai) anos
pai
achega
55f02313eb
Modificáronse 1 ficheiros con 12 adicións e 2 borrados
  1. 12 2
      src/grpc/abstractclient.h

+ 12 - 2
src/grpc/abstractclient.h

@@ -28,7 +28,7 @@
 #include <memory>
 #include <QObject>
 #include <QByteArray>
-#include <QDebug>
+#include <qtprotobuflogging.h>
 
 #include "abstractchannel.h"
 
@@ -50,7 +50,17 @@ protected:
     bool call(const QString &method, const A &arg, R &ret) {
         QByteArray retData;
         if (call(method, arg.serialize(), retData)) {
-            ret.deserialize(retData.mid(5));
+            try {
+                ret.deserialize(retData.mid(5));
+            } catch (std::invalid_argument) {
+                qProtoCritical() << "Response deserialization failed invalid field found";
+                return false;
+            } catch (std::out_of_range) {
+                qProtoCritical() << "Invalid size of received buffer";
+                return false;
+            } catch (...) {
+                throw;
+            }
             return true;
         }
         return false;