Improving error reporting to user
parent
b4e521e171
commit
a42d8934ee
|
@ -26,6 +26,19 @@ pkg_check_modules(CAIRO cairomm-1.0)
|
||||||
|
|
||||||
add_definitions(${GTKMM_CFLAGS_OTHER})
|
add_definitions(${GTKMM_CFLAGS_OTHER})
|
||||||
|
|
||||||
|
# Add JSON Parser via CMake Fetch Content feature
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
FetchContent_Declare(json
|
||||||
|
GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
|
||||||
|
GIT_TAG v3.9.1)
|
||||||
|
|
||||||
|
FetchContent_GetProperties(json)
|
||||||
|
if(NOT json_POPULATED)
|
||||||
|
FetchContent_Populate(json)
|
||||||
|
add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||||
|
endif()
|
||||||
|
|
||||||
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
|
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
|
||||||
# Include CPack packaging settings
|
# Include CPack packaging settings
|
||||||
#include(packaging)
|
#include(packaging)
|
||||||
|
@ -87,6 +100,6 @@ target_link_directories(${PROJECT_TARGET} PRIVATE
|
||||||
${CAIRO_LIBRARY_DIRS}
|
${CAIRO_LIBRARY_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_TARGET} PRIVATE LibCommonMarker LibCommonMarkerExtensions ipfs-http-client Threads::Threads ${CXX_FILESYSTEM_LIBRARIES} ${GTKMM_LIBRARIES} ${CAIRO_LIBRARIES})
|
target_link_libraries(${PROJECT_TARGET} PRIVATE LibCommonMarker LibCommonMarkerExtensions ipfs-http-client Threads::Threads ${CXX_FILESYSTEM_LIBRARIES} ${GTKMM_LIBRARIES} ${CAIRO_LIBRARIES} nlohmann_json::nlohmann_json)
|
||||||
|
|
||||||
install(TARGETS ${PROJECT_TARGET} RUNTIME DESTINATION "bin" COMPONENT applications)
|
install(TARGETS ${PROJECT_TARGET} RUNTIME DESTINATION "bin" COMPONENT applications)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <cmark-gfm.h>
|
#include <cmark-gfm.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include "md-parser.h"
|
#include "md-parser.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
@ -27,12 +28,12 @@ MainWindow::MainWindow()
|
||||||
add_accel_group(accelGroup);
|
add_accel_group(accelGroup);
|
||||||
|
|
||||||
// Connect signals
|
// Connect signals
|
||||||
m_menu.quit.connect(sigc::mem_fun(this, &MainWindow::hide)); /*!< hide main window and therefor closes the app */
|
m_menu.quit.connect(sigc::mem_fun(this, &MainWindow::hide)); /*!< hide main window and therefor closes the app */
|
||||||
m_menu.cut.connect(sigc::mem_fun(m_draw, &Draw::cut)); /*!< Menu item for cut text */
|
m_menu.cut.connect(sigc::mem_fun(m_draw, &Draw::cut)); /*!< Menu item for cut text */
|
||||||
m_menu.copy.connect(sigc::mem_fun(m_draw, &Draw::copy)); /*!< Menu item for copy text */
|
m_menu.copy.connect(sigc::mem_fun(m_draw, &Draw::copy)); /*!< Menu item for copy text */
|
||||||
m_menu.paste.connect(sigc::mem_fun(m_draw, &Draw::paste)); /*!< Menu item for paste text */
|
m_menu.paste.connect(sigc::mem_fun(m_draw, &Draw::paste)); /*!< Menu item for paste text */
|
||||||
//m_menu.del.connect(sigc::mem_fun(m_draw, &Draw::del));
|
//m_menu.del.connect(sigc::mem_fun(m_draw, &Draw::del));
|
||||||
m_menu.select_all.connect(sigc::mem_fun(m_draw, &Draw::selectAll)); /*!< Menu item for selecting all text */
|
m_menu.select_all.connect(sigc::mem_fun(m_draw, &Draw::selectAll)); /*!< Menu item for selecting all text */
|
||||||
//m_menu.find.connect(sigc::mem_fun(this, &MainWindow::find));
|
//m_menu.find.connect(sigc::mem_fun(this, &MainWindow::find));
|
||||||
m_menu.back.connect(sigc::mem_fun(this, &MainWindow::back)); /*!< Menu item for previous page */
|
m_menu.back.connect(sigc::mem_fun(this, &MainWindow::back)); /*!< Menu item for previous page */
|
||||||
m_menu.forward.connect(sigc::mem_fun(this, &MainWindow::forward)); /*!< Menu item for next page */
|
m_menu.forward.connect(sigc::mem_fun(this, &MainWindow::forward)); /*!< Menu item for next page */
|
||||||
|
@ -42,13 +43,13 @@ MainWindow::MainWindow()
|
||||||
m_sourceCodeDialog.signal_response().connect(sigc::mem_fun(m_sourceCodeDialog, &SourceCodeDialog::hide_dialog)); /*!< Close source code dialog */
|
m_sourceCodeDialog.signal_response().connect(sigc::mem_fun(m_sourceCodeDialog, &SourceCodeDialog::hide_dialog)); /*!< Close source code dialog */
|
||||||
m_menu.about.connect(sigc::mem_fun(m_about, &About::show_about)); /*!< Display about dialog */
|
m_menu.about.connect(sigc::mem_fun(m_about, &About::show_about)); /*!< Display about dialog */
|
||||||
m_draw.source_code.connect(sigc::mem_fun(this, &MainWindow::show_source_code_dialog));
|
m_draw.source_code.connect(sigc::mem_fun(this, &MainWindow::show_source_code_dialog));
|
||||||
m_about.signal_response().connect(sigc::mem_fun(m_about, &About::hide_about)); /*!< Close about dialog */
|
m_about.signal_response().connect(sigc::mem_fun(m_about, &About::hide_about)); /*!< Close about dialog */
|
||||||
m_backButton.signal_clicked().connect(sigc::mem_fun(this, &MainWindow::back)); /*!< Button for previous page */
|
m_backButton.signal_clicked().connect(sigc::mem_fun(this, &MainWindow::back)); /*!< Button for previous page */
|
||||||
m_forwardButton.signal_clicked().connect(sigc::mem_fun(this, &MainWindow::forward)); /*!< Button for next page */
|
m_forwardButton.signal_clicked().connect(sigc::mem_fun(this, &MainWindow::forward)); /*!< Button for next page */
|
||||||
m_refreshButton.signal_clicked().connect(sigc::mem_fun(this, &MainWindow::refresh)); /*!< Button for reloading the page */
|
m_refreshButton.signal_clicked().connect(sigc::mem_fun(this, &MainWindow::refresh)); /*!< Button for reloading the page */
|
||||||
m_homeButton.signal_clicked().connect(sigc::mem_fun(this, &MainWindow::go_home)); /*!< Button for home page */
|
m_homeButton.signal_clicked().connect(sigc::mem_fun(this, &MainWindow::go_home)); /*!< Button for home page */
|
||||||
m_addressBar.signal_activate().connect(sigc::mem_fun(this, &MainWindow::address_bar_activate)); /*!< User pressed enter the address bar */
|
m_addressBar.signal_activate().connect(sigc::mem_fun(this, &MainWindow::address_bar_activate)); /*!< User pressed enter the address bar */
|
||||||
|
|
||||||
m_vbox.pack_start(m_menu, false, false, 0);
|
m_vbox.pack_start(m_menu, false, false, 0);
|
||||||
|
|
||||||
// Horizontal bar
|
// Horizontal bar
|
||||||
|
@ -256,9 +257,24 @@ void MainWindow::fetchFromIPFS()
|
||||||
}
|
}
|
||||||
catch (const std::runtime_error &error)
|
catch (const std::runtime_error &error)
|
||||||
{
|
{
|
||||||
std::cerr << "Error: IPFS request failed, with message: " << error.what() << std::endl;
|
std::string errorMessage = std::string(error.what());
|
||||||
// Show not found (or any other issue)
|
std::cerr << "Error: IPFS request failed, with message: " << errorMessage << std::endl;
|
||||||
m_draw.showMessage("Page not found!", "Detailed error message: " + std::string(error.what()));
|
if (errorMessage.starts_with("HTTP request failed with status code"))
|
||||||
|
{
|
||||||
|
// Remove text until ':\n'
|
||||||
|
errorMessage.erase(0, errorMessage.find(':') + 2);
|
||||||
|
auto content = nlohmann::json::parse(errorMessage);
|
||||||
|
std::string message = content.value("Message", "");
|
||||||
|
m_draw.showMessage("Page not found!", message);
|
||||||
|
}
|
||||||
|
else if (errorMessage.starts_with("Couldn't connect to server: Failed to connect to localhost"))
|
||||||
|
{
|
||||||
|
m_draw.showMessage("Please wait...", "IPFS daemon is still spinnng-up, please try to refresh shortly...");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_draw.showMessage("Something went wrong", "Error message: " + std::string(error.what()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +294,7 @@ void MainWindow::openFromDisk()
|
||||||
catch (const std::runtime_error &error)
|
catch (const std::runtime_error &error)
|
||||||
{
|
{
|
||||||
std::cerr << "Error: File request failed, with message: " << error.what() << std::endl;
|
std::cerr << "Error: File request failed, with message: " << error.what() << std::endl;
|
||||||
m_draw.showMessage("Page not found!", "Detailed error message: " + std::string(error.what()));
|
m_draw.showMessage("Page not found!", "Error message: " + std::string(error.what()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue