[evolution-data-server] Include also reason_phrase on libsoup errors
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Include also reason_phrase on libsoup errors
- Date: Fri, 8 Oct 2010 12:52:11 +0000 (UTC)
commit a77bbc3c466fc403ba767fd35921d85a36fae7ee
Author: Milan Crha <mcrha redhat com>
Date: Fri Oct 8 14:42:30 2010 +0200
Include also reason_phrase on libsoup errors
.../backends/webdav/e-book-backend-webdav.c | 35 ++++++++++++++++---
calendar/backends/caldav/e-cal-backend-caldav.c | 26 +++++++++-----
calendar/backends/http/e-cal-backend-http.c | 3 +-
3 files changed, 48 insertions(+), 16 deletions(-)
---
diff --git a/addressbook/backends/webdav/e-book-backend-webdav.c b/addressbook/backends/webdav/e-book-backend-webdav.c
index 322f5b0..c1940ab 100644
--- a/addressbook/backends/webdav/e-book-backend-webdav.c
+++ b/addressbook/backends/webdav/e-book-backend-webdav.c
@@ -187,7 +187,7 @@ download_contact (EBookBackendWebdav *webdav, const gchar *uri)
}
static guint
-upload_contact (EBookBackendWebdav *webdav, EContact *contact)
+upload_contact (EBookBackendWebdav *webdav, EContact *contact, gchar **reason)
{
ESource *source = e_book_backend_get_source (E_BOOK_BACKEND (webdav));
SoupMessage *message;
@@ -268,6 +268,11 @@ upload_contact (EBookBackendWebdav *webdav, EContact *contact)
e_contact_set (contact, E_CONTACT_UID, uri);
}
+ if (reason) {
+ *reason = g_strdup (message->reason_phrase && *message->reason_phrase ? message->reason_phrase :
+ (soup_status_get_phrase (message->status_code) ? soup_status_get_phrase (message->status_code) : _("Unknown error")));
+ }
+
g_object_unref (message);
g_free (request);
g_free (uri);
@@ -301,6 +306,7 @@ e_book_backend_webdav_create_contact (EBookBackend *backend,
EContact *contact;
gchar *uid;
guint status;
+ gchar *status_reason = NULL;
if (priv->mode == E_DATA_BOOK_MODE_LOCAL) {
e_data_book_respond_create (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
@@ -318,7 +324,7 @@ e_book_backend_webdav_create_contact (EBookBackend *backend,
/* kill revision field (might have been set by some other backend) */
e_contact_set (contact, E_CONTACT_REV, NULL);
- status = upload_contact (webdav, contact);
+ status = upload_contact (webdav, contact, &status_reason);
if (status != 201 && status != 204) {
g_object_unref (contact);
if (status == 401 || status == 407) {
@@ -326,12 +332,16 @@ e_book_backend_webdav_create_contact (EBookBackend *backend,
} else {
e_data_book_respond_create (book, opid,
e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR,
- _("Create resource '%s' failed with HTTP status: %d"), uid, status),
+ _("Create resource '%s' failed with HTTP status: %d (%s)"), uid, status, status_reason),
NULL);
}
g_free (uid);
+ g_free (status_reason);
return;
}
+
+ g_free (status_reason);
+
/* PUT request didn't return an etag? try downloading to get one */
if (e_contact_get_const (contact, E_CONTACT_REV) == NULL) {
const gchar *new_uid;
@@ -422,6 +432,7 @@ e_book_backend_webdav_modify_contact (EBookBackend *backend,
const gchar *uid;
const gchar *etag;
guint status;
+ gchar *status_reason = NULL;
if (priv->mode == E_DATA_BOOK_MODE_LOCAL) {
e_data_book_respond_create (book, opid,
@@ -431,11 +442,12 @@ e_book_backend_webdav_modify_contact (EBookBackend *backend,
}
/* modify contact */
- status = upload_contact (webdav, contact);
+ status = upload_contact (webdav, contact, &status_reason);
if (status != 201 && status != 204) {
g_object_unref (contact);
if (status == 401 || status == 407) {
e_data_book_respond_remove_contacts (book, opid, webdav_handle_auth_request (webdav), NULL);
+ g_free (status_reason);
return;
}
/* data changed on server while we were editing */
@@ -445,16 +457,20 @@ e_book_backend_webdav_modify_contact (EBookBackend *backend,
e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR,
"Contact on server changed -> not modifying"),
NULL);
+ g_free (status_reason);
return;
}
e_data_book_respond_modify (book, opid,
e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR,
- "Modify contact failed with HTTP status: %d", status),
+ "Modify contact failed with HTTP status: %d (%s)", status, status_reason),
NULL);
+ g_free (status_reason);
return;
}
+ g_free (status_reason);
+
uid = e_contact_get_const (contact, E_CONTACT_UID);
e_book_backend_cache_remove_contact (priv->cache, uid);
@@ -857,9 +873,16 @@ download_contacts (EBookBackendWebdav *webdav, EFlag *running,
return webdav_handle_auth_request (webdav);
}
if (status != 207) {
+ GError *error;
+
+ error = e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, "PROPFIND on webdav failed with HTTP status %d (%s)",
+ status,
+ message->reason_phrase && *message->reason_phrase ? message->reason_phrase :
+ (soup_status_get_phrase (message->status_code) ? soup_status_get_phrase (message->status_code) : _("Unknown error")));
+
g_object_unref (message);
g_free (new_ctag);
- return e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, "PROPFIND on webdav failed with HTTP status %d", status);
+ return error;
}
if (message->response_body == NULL) {
g_warning("No response body in webdav PROPFIND result");
diff --git a/calendar/backends/caldav/e-cal-backend-caldav.c b/calendar/backends/caldav/e-cal-backend-caldav.c
index ae0a394..ef66cf7 100644
--- a/calendar/backends/caldav/e-cal-backend-caldav.c
+++ b/calendar/backends/caldav/e-cal-backend-caldav.c
@@ -502,13 +502,15 @@ quote_etag (const gchar *etag)
/* ************************************************************************* */
static gboolean
-status_code_to_result (guint status_code, ECalBackendCalDAVPrivate *priv, GError **perror)
+status_code_to_result (SoupMessage *message, ECalBackendCalDAVPrivate *priv, GError **perror)
{
- if (SOUP_STATUS_IS_SUCCESSFUL (status_code)) {
+ g_return_val_if_fail (message != NULL, FALSE);
+
+ if (SOUP_STATUS_IS_SUCCESSFUL (message->status_code)) {
return TRUE;
}
- switch (status_code) {
+ switch (message->status_code) {
case 404:
g_propagate_error (perror, EDC_ERROR (NoSuchCal));
@@ -527,7 +529,13 @@ status_code_to_result (guint status_code, ECalBackendCalDAVPrivate *priv, GErro
default:
d(g_debug ("CalDAV:%s: Unhandled status code %d\n", G_STRFUNC, status_code));
- g_propagate_error (perror, e_data_cal_create_error_fmt (OtherError, _("Unexpected HTTP status code %d returned"), status_code));
+ g_propagate_error (perror,
+ e_data_cal_create_error_fmt (
+ OtherError,
+ _("Unexpected HTTP status code %d returned (%s)"),
+ message->status_code,
+ message->reason_phrase && *message->reason_phrase ? message->reason_phrase :
+ (soup_status_get_phrase (message->status_code) ? soup_status_get_phrase (message->status_code) : _("Unknown error"))));
}
return FALSE;
@@ -988,7 +996,7 @@ caldav_server_open_calendar (ECalBackendCalDAV *cbdav, GError **perror)
send_and_handle_redirection (priv->session, message, NULL);
if (!SOUP_STATUS_IS_SUCCESSFUL (message->status_code)) {
- status_code_to_result (message->status_code, priv, perror);
+ status_code_to_result (message, priv, perror);
g_object_unref (message);
return FALSE;
}
@@ -1265,7 +1273,7 @@ caldav_server_get_object (ECalBackendCalDAV *cbdav, CalDAVObject *object, GError
send_and_handle_redirection (priv->session, message, NULL);
if (!SOUP_STATUS_IS_SUCCESSFUL (message->status_code)) {
- status_code_to_result (message->status_code, priv, perror);
+ status_code_to_result (message, priv, perror);
g_warning ("Could not fetch object '%s' from server, status:%d (%s)", uri, message->status_code, soup_status_get_phrase (message->status_code) ? soup_status_get_phrase (message->status_code) : "Unknown code");
g_object_unref (message);
@@ -1329,7 +1337,7 @@ caldav_post_freebusy (ECalBackendCalDAV *cbdav, const gchar *url, gchar **post_f
send_and_handle_redirection (priv->session, message, NULL);
if (!SOUP_STATUS_IS_SUCCESSFUL (message->status_code)) {
- status_code_to_result (message->status_code, priv, error);
+ status_code_to_result (message, priv, error);
g_warning ("Could not post free/busy request to '%s', status:%d (%s)", url, message->status_code, soup_status_get_phrase (message->status_code) ? soup_status_get_phrase (message->status_code) : "Unknown code");
g_object_unref (message);
@@ -1404,7 +1412,7 @@ caldav_server_put_object (ECalBackendCalDAV *cbdav, CalDAVObject *object, icalco
g_free (uri);
}
- if (status_code_to_result (message->status_code, priv, perror)) {
+ if (status_code_to_result (message, priv, perror)) {
gboolean was_get = FALSE;
hdr = soup_message_headers_get (message->response_headers, "ETag");
@@ -1485,7 +1493,7 @@ caldav_server_delete_object (ECalBackendCalDAV *cbdav, CalDAVObject *object, GEr
send_and_handle_redirection (priv->session, message, NULL);
- status_code_to_result (message->status_code, priv, perror);
+ status_code_to_result (message, priv, perror);
g_object_unref (message);
}
diff --git a/calendar/backends/http/e-cal-backend-http.c b/calendar/backends/http/e-cal-backend-http.c
index 5815f63..39dc4b6 100644
--- a/calendar/backends/http/e-cal-backend-http.c
+++ b/calendar/backends/http/e-cal-backend-http.c
@@ -374,7 +374,8 @@ retrieval_done (SoupSession *session, SoupMessage *msg, ECalBackendHttp *cbhttp)
if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
if (!priv->opened) {
e_cal_backend_notify_error (E_CAL_BACKEND (cbhttp),
- soup_status_get_phrase (msg->status_code));
+ msg->reason_phrase && *msg->reason_phrase ? msg->reason_phrase :
+ (soup_status_get_phrase (msg->status_code) ? soup_status_get_phrase (msg->status_code) : _("Unknown error")));
}
empty_cache (cbhttp);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]