[couchdb-glib] Send errors from libsoup back to the caller



commit 8b95743ee463d7557879b0a275ced81f1a9b81b7
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Tue Aug 18 00:26:51 2009 +0200

    Send errors from libsoup back to the caller

 couchdb-glib/utils.c |   14 +++++++++++---
 couchdb-glib/utils.h |    3 +++
 2 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/couchdb-glib/utils.c b/couchdb-glib/utils.c
index 2b4f20d..ef5ecfd 100644
--- a/couchdb-glib/utils.c
+++ b/couchdb-glib/utils.c
@@ -51,6 +51,8 @@ parse_json_response (SoupMessage *http_message, GError **error)
 						 error)) {
 			g_object_unref (G_OBJECT (json_parser));
 			json_parser = NULL;
+
+			g_set_error (error, COUCHDB_ERROR, -1, "Invalid JSON response");
 		}
 
 		g_string_free (str, TRUE);
@@ -59,9 +61,15 @@ parse_json_response (SoupMessage *http_message, GError **error)
 	return json_parser;
 }
 
-static void
-set_error_from_soup (GError **error, guint status)
+GQuark
+couchdb_error_quark (void)
 {
+	static GQuark error;
+
+	if (!error)
+		error = g_quark_from_static_string ("couchdb_glib");
+
+	return error;
 }
 
 JsonParser *
@@ -82,7 +90,7 @@ send_message_and_parse (CouchDB *couchdb, const char *method, const char *url, c
 	if (SOUP_STATUS_IS_SUCCESSFUL (status)) {
 	       	parser = parse_json_response (http_message, error);
 	} else {
-		set_error_from_soup (error, status);
+		g_set_error (error, COUCHDB_ERROR, status, http_message->reason_phrase);
 	}
 
 	return parser;
diff --git a/couchdb-glib/utils.h b/couchdb-glib/utils.h
index be684e9..e79be3f 100644
--- a/couchdb-glib/utils.h
+++ b/couchdb-glib/utils.h
@@ -81,6 +81,9 @@ CouchDBStructField *couchdb_struct_field_new_from_json_object (JsonObject *json_
  * Utility functions
  */
 
+#define COUCHDB_ERROR couchdb_error_quark()
+GQuark      couchdb_error_quark (void);
+
 JsonParser *send_message_and_parse (CouchDB *couchdb,
 				    const char *method,
 				    const char *url,



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