From b57b6423aebc8f0aaeb4913f1a010e821dc6c456 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 20 May 2014 11:42:24 +0200 Subject: [PATCH] Relay Torus HTTP error --- src/filter_zoom.cpp | 24 +++++++++++++++--------- src/torus.cpp | 12 +++++++++++- src/torus.hpp | 3 ++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/filter_zoom.cpp b/src/filter_zoom.cpp index a29f243..5a44469 100644 --- a/src/filter_zoom.cpp +++ b/src/filter_zoom.cpp @@ -1257,15 +1257,17 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( sptr = it->second; else if (torus_url.length() > 0) { + std::string torus_addinfo; std::string torus_query = "udb==" + torus_db; xmlDoc *doc = mp::get_searchable(package,torus_url, torus_db, torus_query, - realm, m_p->proxy); + realm, m_p->proxy, + torus_addinfo); if (!doc) { *error = YAZ_BIB1_UNSPECIFIED_ERROR; - *addinfo = odr_strdup(odr, "Torus server unavailable or " - "incorrectly configured"); + if (torus_addinfo.length()) + *addinfo = odr_strdup(odr, torus_addinfo.c_str()); BackendPtr b; return b; } @@ -2013,10 +2015,12 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::explain_search(mp::Package &package, else if (query->which == Z_Query_type_104 && query->u.type_104->which == Z_External_CQL) { + std::string torus_addinfo; std::string torus_query(query->u.type_104->u.cql); xmlDoc *doc = mp::get_searchable(package, torus_url, "", torus_query, - realm, m_p->proxy); + realm, m_p->proxy, + torus_addinfo); if (m_p->explain_xsp) { xmlDoc *rec_res = xsltApplyStylesheet(m_p->explain_xsp, doc, 0); @@ -2027,8 +2031,8 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::explain_search(mp::Package &package, if (!doc) { *error = YAZ_BIB1_UNSPECIFIED_ERROR; - *addinfo = odr_strdup(odr, "Torus server unavailable or " - "incorrectly configured"); + if (torus_addinfo.length()) + *addinfo = odr_strdup(odr, torus_addinfo.c_str()); } else { @@ -2633,14 +2637,16 @@ void yf::Zoom::Frontend::auth(mp::Package &package, Z_InitRequest *req, std::string dummy_db; std::string dummy_realm; + std::string torus_addinfo; xmlDoc *doc = mp::get_searchable(package, m_p->torus_auth_url, dummy_db, - torus_query, dummy_realm, m_p->proxy); + torus_query, dummy_realm, m_p->proxy, + torus_addinfo); if (!doc) { // something fundamental broken in lookup. *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR; - *addinfo = odr_strdup(odr, "zoom: torus server unavailable or " - "incorrectly configured."); + if (torus_addinfo.length()) + *addinfo = odr_strdup(odr, torus_addinfo.c_str()); return; } const xmlNode *ptr = xmlDocGetRootElement(doc); diff --git a/src/torus.cpp b/src/torus.cpp index 5352b9a..5400850 100644 --- a/src/torus.cpp +++ b/src/torus.cpp @@ -31,7 +31,8 @@ xmlDoc *mp::get_searchable(mp::Package &package, std::string url_template, const std::string &db, const std::string &query, const std::string &realm, - const std::string &proxy) + const std::string &proxy, + std::string &addinfo) { // http://mk2.indexdata.com/torus2/searchable/records/?query=udb%3d%db // or @@ -76,19 +77,28 @@ xmlDoc *mp::get_searchable(mp::Package &package, package.log("zoom", YLOG_LOG, "Torus: %s OK", url_template.c_str()); else + { package.log("zoom", YLOG_WARN, "Torus: %s FAIL. XML parse failed", url_template.c_str()); + addinfo = "Torus: XML parse failed"; + } } else { + addinfo = "Torus: "; if (http_response) { package.log("zoom", YLOG_WARN, "Torus: %s FAIL. HTTP code %d", url_template.c_str(), http_response->code); + addinfo += std::string(http_response->content_buf, + http_response->content_len); } else + { + addinfo += "unknown error"; package.log("zoom", YLOG_WARN, "Torus: %s FAIL. No HTTP response", url_template.c_str()); + } } if (http_response && http_response->content_buf) diff --git a/src/torus.hpp b/src/torus.hpp index 76199b8..0db2bf8 100644 --- a/src/torus.hpp +++ b/src/torus.hpp @@ -30,7 +30,8 @@ namespace metaproxy_1 { std::string url_template, const std::string &db, const std::string &query, const std::string &realm, - const std::string &proxy); + const std::string &proxy, + std::string &addinfo); } #endif -- 1.7.10.4