aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-09-09 15:42:58 +0200
committerneodarz <neodarz@neodarz.net>2019-09-09 15:42:58 +0200
commit5b66830ca806e00f415d6ee83b15e410130de371 (patch)
tree98851166c5d54eb7bd9f7d66543987be20a2c074
parent1b922f7319f821fe3daf302a8c68131aaa94f586 (diff)
downloadumosapicpp-5b66830ca806e00f415d6ee83b15e410130de371.tar.xz
umosapicpp-5b66830ca806e00f415d6ee83b15e410130de371.zip
Add some adjustement to make server more stable
-rw-r--r--api/umosapi.cpp18
-rw-r--r--main.cpp2
2 files changed, 13 insertions, 7 deletions
diff --git a/api/umosapi.cpp b/api/umosapi.cpp
index af58b37..737df24 100644
--- a/api/umosapi.cpp
+++ b/api/umosapi.cpp
@@ -63,8 +63,11 @@ void service_error_handler( const int, const exception& e, const shared_ptr< Ses
{
std::string message = "Backend Service is dead: ";
message += e.what();
- if ( session->is_open( ) )
- session->close( 500, message, { { "Content-Length", ::to_string(message.length()) } } );
+ if ( session ) {
+ if ( session->is_open( ) ) {
+ session->close( 500, message, { { "Content-Length", ::to_string(message.length()) } } );
+ }
+ }
fprintf( stderr, "ERROR: %s.\n", message.c_str() );
}
@@ -274,12 +277,12 @@ void UmosapiService::createResource() {
set_method_handler("GET", retrieveAll);
produce("application/json");
parameter("mcollection", "Name of the collection where the uobject are located");
- set_error_handler(resource_error_handler);
+ set_error_handler(&resource_error_handler);
set_method_handler("POST", addUObject);
consume("application/json");
parameter("mcollection", "Name of the collection where the uobject are located");
parameter("body", "UObject to add", "UObjectSended");
- set_error_handler(resource_error_handler);
+ set_error_handler(&resource_error_handler);
publish();
set_path("/v2/{mcollection: .*}/{oid: .*}");
@@ -287,7 +290,7 @@ void UmosapiService::createResource() {
produce("application/json");
parameter("mcollection", "Name of the collection where the uobject are located" );
parameter("oid", "MongoDB oid of the uobject");
- set_error_handler(resource_error_handler);
+ set_error_handler(&resource_error_handler);
publish();
set_path("/v2/{mcollection: .*}/{key: .*}/{value: .*}");
@@ -296,7 +299,7 @@ void UmosapiService::createResource() {
parameter("mcollection", "Name of the collection where the uobject are located");
parameter("key", "Key of uobject to search, ex: kill or total.kill");
parameter("value", "Value of uobject to search, ex: 42");
- set_error_handler(resource_error_handler);
+ set_error_handler(&resource_error_handler);
publish();
_service.set_error_handler( service_error_handler );
@@ -306,12 +309,13 @@ void UmosapiService::retrieveAll( const shared_ptr<Session> session ){
auto jsonObjects = json_object_new_array();
const auto& request = session->get_request( );
auto json_string = uobject::retrieveAll(request->get_path_parameter( "mcollection" ), jsonObjects);
- json_object_put(jsonObjects);
session->close( OK, json_string, {
{ "Content-Length", ::to_string(json_string.length()) },
{ "Content-Type", "application/json" }
});
+ json_object_put(jsonObjects);
+
}
void UmosapiService::addUObject( const shared_ptr<Session> session ){
diff --git a/main.cpp b/main.cpp
index 05a6232..9cf4127 100644
--- a/main.cpp
+++ b/main.cpp
@@ -77,4 +77,6 @@ int main(int argc, char *argv[]) {
umosapi.init();
umosapi.start(std::stoi(config["port"]), thr);
+ return EXIT_SUCCESS;
+
}