[libgovirt] proxy: Set detailed error message for async call



commit d054bfec057c1f120094b827c45038a401eec08c
Author: Eduardo Lima (Etrunko) <etrunko redhat com>
Date:   Wed Jul 11 15:42:16 2018 -0300

    proxy: Set detailed error message for async call
    
    The rest API returns more detailed error messages with the result, not
    only the literal corresponding to the value. If this is the case, we set
    a new error message and return it.
    
    For example, before this change, virt-viewer showed a dialog with a
    vague 'Bad Request' message, and now a much more detailed 'Operation
    Failed: query execution failed due to insufficient permissions.'
    
    Signed-off-by: Eduardo Lima (Etrunko) <etrunko redhat com>

 govirt/ovirt-proxy.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/govirt/ovirt-proxy.c b/govirt/ovirt-proxy.c
index 73c4d4a..2157188 100644
--- a/govirt/ovirt-proxy.c
+++ b/govirt/ovirt-proxy.c
@@ -238,6 +238,22 @@ call_async_cancelled_cb (G_GNUC_UNUSED GCancellable *cancellable,
 }
 
 
+static void rest_call_async_set_error(RestProxyCall *call, GSimpleAsyncResult *result, const GError *error)
+{
+    GError *local_error = NULL;
+    RestXmlNode *root = ovirt_rest_xml_node_from_call(call);
+
+    if (root != NULL && ovirt_utils_gerror_from_xml_fault(root, &local_error)) {
+        g_debug("ovirt_rest_call_async(): %s", local_error->message);
+        g_simple_async_result_set_from_error(result, local_error);
+        g_clear_error(&local_error);
+    } else {
+        g_simple_async_result_set_from_error(result, error);
+    }
+
+    rest_xml_node_unref(root);
+}
+
 static void
 call_async_cb(RestProxyCall *call, const GError *error,
               G_GNUC_UNUSED GObject *weak_object,
@@ -247,7 +263,7 @@ call_async_cb(RestProxyCall *call, const GError *error,
     GSimpleAsyncResult *result = data->result;
 
     if (error != NULL) {
-        g_simple_async_result_set_from_error(result, error);
+        rest_call_async_set_error(call, result, error);
     } else {
         GError *call_error = NULL;
         gboolean callback_result = TRUE;
@@ -257,7 +273,7 @@ call_async_cb(RestProxyCall *call, const GError *error,
                                                   data->call_user_data,
                                                   &call_error);
             if (call_error != NULL) {
-                g_simple_async_result_set_from_error(result, call_error);
+                rest_call_async_set_error(call, result, call_error);
             }
         }
 


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