[core] Use util::readFile for Local and Asset file sources

Use exception free util::readFile instead of util::read_file for
LocalFileSource and AssetFileSource implementations.
This commit is contained in:
Alexander Shalamov
2018-10-09 17:17:12 +03:00
parent fed201aaed
commit f076a1fe39
2 changed files with 10 additions and 8 deletions

View File

@@ -44,12 +44,13 @@ public:
} else if (result == -1 && errno == ENOENT) {
response.error = std::make_unique<Response::Error>(Response::Error::Reason::NotFound);
} else {
try {
response.data = std::make_shared<std::string>(util::read_file(path));
} catch (...) {
auto data = util::readFile(path);
if (!data) {
response.error = std::make_unique<Response::Error>(
Response::Error::Reason::Other,
util::toString(std::current_exception()));
std::string("Cannot read file ") + path);
} else {
response.data = std::make_shared<std::string>(std::move(*data));
}
}

View File

@@ -46,12 +46,13 @@ public:
} else if (result == -1 && errno == ENOENT) {
response.error = std::make_unique<Response::Error>(Response::Error::Reason::NotFound);
} else {
try {
response.data = std::make_shared<std::string>(util::read_file(path));
} catch (...) {
auto data = util::readFile(path);
if (!data) {
response.error = std::make_unique<Response::Error>(
Response::Error::Reason::Other,
util::toString(std::current_exception()));
std::string("Cannot read file ") + path);
} else {
response.data = std::make_shared<std::string>(std::move(*data));
}
}