Skip to content

Commit

Permalink
feat: basic error exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
nickelpro committed Oct 26, 2024
1 parent 525ef71 commit 2e4d798
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ option(NANOROUTE_STRIP "Run system strip on compiled module" ON)
find_package(Python3 3.13 REQUIRED COMPONENTS Development.Module)

Python3_add_library(nanoroute MODULE)
target_link_libraries(nanoroute PRIVATE
Python3::Module
)
target_compile_features(nanoroute PRIVATE cxx_std_23)
set_target_properties(nanoroute PROPERTIES CXX_VISIBILITY_PRESET hidden)

Expand Down
9 changes: 8 additions & 1 deletion src/PyRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <array>
#include <cstddef>
#include <stdexcept>
#include <string_view>
#include <vector>

Expand Down Expand Up @@ -134,7 +135,13 @@ PyObject* PyRouter::register_route(PyObject* self, PyObject* const* args,

for(auto meth : rg->meths) {
Py_INCREF(pyo);
rg->pyrouter->httprouter_.reg_route(meth, route, pyo);
try {
rg->pyrouter->httprouter_.reg_route(meth, route, pyo);
} catch(const std::exception& e) {
Py_DECREF(pyo);
PyErr_SetString(PyExc_TypeError, e.what());
return nullptr;
}
}

Py_INCREF(pyo);
Expand Down

0 comments on commit 2e4d798

Please sign in to comment.