From ef6fabb7a6281420f0d40845dae9826c97df96e6 Mon Sep 17 00:00:00 2001 From: septi Date: Fri, 27 Mar 2020 11:44:22 +0000 Subject: [PATCH] Add exception handling through SWIG --- Makefile | 4 ++-- odata_client_python.i | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f281714..e3b74e6 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ clean: # 1. get a proper url go to https://services.odata.org/v4/TripPinServiceRW # 2. replace the url in the below call test: - LD_LIBRARY_PATH=${PWD}/odatacpp/output python3.6 codegen_tools.py 'https://services.odata.org/v4/(S(sbe2f21zvvhp33ytwqndereb))/TripPinServiceRW/' TripPin + LD_LIBRARY_PATH=${PWD}/odatacpp/output python3.6m codegen_tools.py 'https://services.odata.org/v4/(S(sbe2f21zvvhp33ytwqndereb))/TripPinServiceRW/' TripPin ## pyhon3.x @@ -46,5 +46,5 @@ test: all_swig: odata_client_python.i swig -python -c++ -Wall -DODATACPP_CLIENT_API -I/usr/include -Iodatacpp/include -o odata_client_python_swig_wrap.cxx $< $(CXX) odata_client_python_swig_wrap.cxx -o odata_client_python_wrap.o -c -g -fPIC -shared -std=c++11 -fno-strict-aliasing -O2 -I/usr/include/python3.6 -Iodatacpp/include -I/usr/include/openssl -I/usr/include/libxml2 - $(CXX) odata_client_python_wrap.o -o _odata_client_python.so -g -shared -Lodatacpp/output -L/usr/lib/x86_64-linux-gnu -lodata-client -lpython3.6 -lcpprest -lboost_system -lssl -lcrypto + $(CXX) odata_client_python_wrap.o -o _odata_client_python.so -g -shared -Lodatacpp/output -L/usr/lib/x86_64-linux-gnu -lodata-client -lpython3.6m -lcpprest -lboost_system -lssl -lcrypto diff --git a/odata_client_python.i b/odata_client_python.i index 774b6a2..12d558b 100644 --- a/odata_client_python.i +++ b/odata_client_python.i @@ -19,6 +19,8 @@ %include %include +%include + %include namespace web { @@ -27,7 +29,6 @@ namespace web { } } - SHAREDPTR(odata::edm::edm_named_type) SHAREDPTR(odata::edm::edm_primitive_type) SHAREDPTR(odata::edm::edm_property_type) @@ -113,6 +114,18 @@ namespace odata { %include "odata/communication/http_communication.h" %include "odata/client/odata_client_options.h" + +%exception odata::client::odata_client::send_data_to_server { + try { + $action + } catch (odata::communication::service_exception &e) { + std::string msg = utility::conversions::scan_string(e.what()); + SWIG_exception(SWIG_RuntimeError, msg.c_str()); + } catch (std::invalid_argument &e) { + SWIG_exception(SWIG_AttributeError, e.what()); + } +} + %include "odata/client/odata_client.h" %extend odata::edm::edm_entity_container { @@ -186,10 +199,19 @@ namespace pplx { template class task { public: - _ReturnType get() const throw(odata::communication::service_exception); + _ReturnType get() const; }; } +%exception pplx::task::get { + try { + $action + } catch (odata::communication::service_exception &e) { + std::string msg = utility::conversions::scan_string(e.what()); + SWIG_exception(SWIG_RuntimeError, msg.c_str()); + } +} + %template(task_edm_model) pplx::task< std::shared_ptr< ::odata::edm::edm_model > >; %template(task_odata_entity_values) pplx::task< std::vector< std::shared_ptr< ::odata::core::odata_entity_value > > >; %template(task_odata_values) pplx::task< std::vector< std::shared_ptr< ::odata::core::odata_value > > >;