From 743f77d3161676c9c62ac648d8d85fac93da6259 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 10 Mar 2018 13:45:40 +0000 Subject: Tighten error handling --- service/apiImpl.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'service/apiImpl.cpp') diff --git a/service/apiImpl.cpp b/service/apiImpl.cpp index 9795769..42a7918 100644 --- a/service/apiImpl.cpp +++ b/service/apiImpl.cpp @@ -42,7 +42,7 @@ namespace MirrorSearch { void curlErrorHandler(const std::string & fn, const char * errbuf, const P & ... p) { - throw XmlError(Fmt::get(fn, errbuf, p...)); + throw CurlError(Fmt::get(fn, errbuf, p...)); } template auto cEHB(const char * errbuf, const P & ... p) @@ -97,11 +97,17 @@ namespace MirrorSearch { CESSO(curl, CURLOPT_ACCEPT_ENCODING, ""); CESSO(curl, CURLOPT_HTTP_CONTENT_DECODING, 1L); CESSO(curl, CURLOPT_TCP_FASTOPEN, 1L); + CESSO(curl, CURLOPT_FAILONERROR, 1L); if (curl_easy_perform(curl.get()) != CURLE_OK) { curlErrorHandler(failingFunction((void*)&curl_easy_perform), errbuf, url); } - BOOST_VERIFY_MSG(ctx, "No ctx and no previous error should never happen."); + if (!ctx) { + throw CurlError("Did not retrieve any data."); + } htmlParseChunk(ctx.get(), "", 0, 1); + if (!ctx->myDoc) { + throw XmlError("Could not construct a document."); + } UPtr doc = { ctx->myDoc, xmlFreeDoc }; return doc; @@ -128,6 +134,9 @@ namespace MirrorSearch { auto doc = getDoc(s, fn); auto xpathCtx = getXPathCxt(doc); auto xpathObj = getXPathObj(s->listxpath, xpathCtx, xmlXPathObjectType::XPATH_NODESET); + if (!xpathObj->nodesetval) { + throw XmlError("Nodeset is null"); + } log->messagebf(LOG::INFO, "%d nodes matched %s", xpathObj->nodesetval->nodeNr, s->listxpath); for (int row = 0; row < xpathObj->nodesetval->nodeNr; row += 1) { xpathCtx->node = xpathObj->nodesetval->nodeTab[row]; -- cgit v1.2.3