Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Commit

Permalink
Add exception handling through SWIG
Browse files Browse the repository at this point in the history
  • Loading branch information
septi committed Mar 27, 2020
1 parent 150fcff commit ef6fabb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

26 changes: 24 additions & 2 deletions odata_client_python.i
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
%include <std_vector.i>
%include <std_shared_ptr.i>

%include <exception.i>

%include <pycontainer.swg>

namespace web {
Expand All @@ -27,7 +29,6 @@ namespace web {
}
}


SHAREDPTR(odata::edm::edm_named_type)
SHAREDPTR(odata::edm::edm_primitive_type)
SHAREDPTR(odata::edm::edm_property_type)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -186,10 +199,19 @@ namespace pplx {
template<class _ReturnType>
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 > > >;
Expand Down

0 comments on commit ef6fabb

Please sign in to comment.