Fix try/catch
parent
2f4b319e39
commit
dedefd8260
|
@ -20,11 +20,11 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|||
find_package(CURL REQUIRED)
|
||||
include_directories(${CURL_INCLUDE_DIRS})
|
||||
|
||||
include_directories("include")
|
||||
|
||||
# Targets
|
||||
set(IPFS_API_LIBNAME ipfs-http-client)
|
||||
|
||||
include_directories("include")
|
||||
|
||||
# To build and install a shared library: "cmake -DBUILD_SHARED_LIBS:BOOL=ON ..."
|
||||
add_library(${IPFS_API_LIBNAME}
|
||||
src/client.cc
|
||||
|
|
|
@ -1,24 +1,15 @@
|
|||
#include "network.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
// Connect to IPFS daemon
|
||||
Network::Network()
|
||||
: 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;
|
||||
}
|
||||
}
|
||||
Network::Network(): client("localhost", 5001) {}
|
||||
|
||||
void Network::fetchFile(const std::string& path, std::iostream* response) {
|
||||
if (client != NULL)
|
||||
client->FilesGet(path, response);
|
||||
try {
|
||||
client.FilesGet(path, response);
|
||||
} catch (const std::runtime_error &error) {
|
||||
std::cerr << "IPFS Deamon is most likely down: " << error.what() << std::endl;
|
||||
}
|
||||
}
|
|
@ -16,6 +16,6 @@ public:
|
|||
|
||||
void fetchFile(const std::string& path, std::iostream* response);
|
||||
private:
|
||||
ipfs::Client *client;
|
||||
ipfs::Client client;
|
||||
};
|
||||
#endif
|
Loading…
Reference in New Issue