diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-03-10 13:45:40 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-03-10 13:45:40 +0000 |
commit | 743f77d3161676c9c62ac648d8d85fac93da6259 (patch) | |
tree | 7f89ebafc57009ba98c0c7e21e5226c28d830a0a /service/apiImpl.cpp | |
parent | Configure install rules (diff) | |
download | mirrorsearch-743f77d3161676c9c62ac648d8d85fac93da6259.tar.bz2 mirrorsearch-743f77d3161676c9c62ac648d8d85fac93da6259.tar.xz mirrorsearch-743f77d3161676c9c62ac648d8d85fac93da6259.zip |
Tighten error handling
Diffstat (limited to 'service/apiImpl.cpp')
-rw-r--r-- | service/apiImpl.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
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<typename Fmt, typename ... P> 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<Read>(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<xmlDoc> 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]; |