Fix try/catch

master
Melroy van den Berg 2020-12-06 04:22:27 +01:00
parent 2f4b319e39
commit dedefd8260
3 changed files with 10 additions and 19 deletions

View File

@ -20,11 +20,11 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(CURL REQUIRED) find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIRS}) include_directories(${CURL_INCLUDE_DIRS})
include_directories("include")
# Targets # Targets
set(IPFS_API_LIBNAME ipfs-http-client) set(IPFS_API_LIBNAME ipfs-http-client)
include_directories("include")
# To build and install a shared library: "cmake -DBUILD_SHARED_LIBS:BOOL=ON ..." # To build and install a shared library: "cmake -DBUILD_SHARED_LIBS:BOOL=ON ..."
add_library(${IPFS_API_LIBNAME} add_library(${IPFS_API_LIBNAME}
src/client.cc src/client.cc

View File

@ -1,24 +1,15 @@
#include "network.h" #include "network.h"
#include <sstream> #include <sstream>
#include <iostream>
// Connect to IPFS daemon // Connect to IPFS daemon
Network::Network() Network::Network(): client("localhost", 5001) {}
: client(NULL)
{
try {
client = new ipfs::Client("localhost", 5001);
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
// Something else
client = NULL;
} catch (...) {
std::cerr << "Something else!?" << std::endl;
client = NULL;
}
}
void Network::fetchFile(const std::string& path, std::iostream* response) { void Network::fetchFile(const std::string& path, std::iostream* response) {
if (client != NULL) try {
client->FilesGet(path, response); client.FilesGet(path, response);
} catch (const std::runtime_error &error) {
std::cerr << "IPFS Deamon is most likely down: " << error.what() << std::endl;
}
} }

View File

@ -16,6 +16,6 @@ public:
void fetchFile(const std::string& path, std::iostream* response); void fetchFile(const std::string& path, std::iostream* response);
private: private:
ipfs::Client *client; ipfs::Client client;
}; };
#endif #endif