From e0c49c47026a19dc5e2dc073c01ec4f75da28570 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 24 Aug 2020 18:14:12 +0200 Subject: [PATCH] Make Document::extract_location() more robust. --- src/document.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/document.cpp b/src/document.cpp index 81b30cb..e53f33b 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -259,11 +260,23 @@ string Document::remove_html(string html) const string Document::extract_location(const RestClient::HeaderFields &headers) const { - string location{headers.at("Location")}; - if (location.empty()) + string location; + try { - location = headers.at("location"); + location = headers.at("Location"); } + catch (const std::out_of_range &) + { + try + { + location = headers.at("location"); + } + catch (const std::out_of_range &) + { + throw std::runtime_error{"Could not extract new feed location."}; + } + } + return location; }