Skip to content

Commit

Permalink
[C++][Pistache] Catch exception instead of runtime_error (OpenAPITool…
Browse files Browse the repository at this point in the history
…s#3225)

* [C++][Pistache] Replace runtime_error with std::exception

* [C++][Pistache] Update Petstore sample

* [C++][Pistache] Fix catch-value warning
  • Loading branch information
muttleyxd authored and etherealjoy committed Jun 26, 2019
1 parent 7af2bc8 commit 68a5fa4
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool fromStringValue(const std::string &inStr, int32_t &value){
try {
value = std::stoi( inStr );
}
catch (const std::invalid_argument) {
catch (const std::invalid_argument&) {
return false;
}
return true;
Expand All @@ -49,7 +49,7 @@ bool fromStringValue(const std::string &inStr, int64_t &value){
try {
value = std::stol( inStr );
}
catch (const std::invalid_argument) {
catch (const std::invalid_argument&) {
return false;
}
return true;
Expand All @@ -65,7 +65,7 @@ bool fromStringValue(const std::string &inStr, float &value){
try {
value = std::stof( inStr );
}
catch (const std::invalid_argument) {
catch (const std::invalid_argument&) {
return false;
}
return true;
Expand All @@ -75,7 +75,7 @@ bool fromStringValue(const std::string &inStr, double &value){
try {
value = std::stod( inStr );
}
catch (const std::invalid_argument) {
catch (const std::invalid_argument&) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.2-SNAPSHOT
4.0.3-SNAPSHOT
16 changes: 8 additions & 8 deletions samples/server/petstore/cpp-pistache/api/PetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -78,7 +78,7 @@ void PetApi::delete_pet_handler(const Pistache::Rest::Request &request, Pistache
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -103,7 +103,7 @@ void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request,
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -128,7 +128,7 @@ void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, P
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -145,7 +145,7 @@ void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request &request, Pista
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -165,7 +165,7 @@ void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -179,7 +179,7 @@ void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request &request
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -193,7 +193,7 @@ void PetApi::upload_file_handler(const Pistache::Rest::Request &request, Pistach
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand Down
8 changes: 4 additions & 4 deletions samples/server/petstore/cpp-pistache/api/StoreApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void StoreApi::delete_order_handler(const Pistache::Rest::Request &request, Pist
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -66,7 +66,7 @@ void StoreApi::get_inventory_handler(const Pistache::Rest::Request &request, Pis
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -83,7 +83,7 @@ void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request &request, P
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -103,7 +103,7 @@ void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pista
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand Down
16 changes: 8 additions & 8 deletions samples/server/petstore/cpp-pistache/api/UserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -77,7 +77,7 @@ void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Reques
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -96,7 +96,7 @@ void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -113,7 +113,7 @@ void UserApi::delete_user_handler(const Pistache::Rest::Request &request, Pistac
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -130,7 +130,7 @@ void UserApi::get_user_by_name_handler(const Pistache::Rest::Request &request, P
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand Down Expand Up @@ -163,7 +163,7 @@ void UserApi::login_user_handler(const Pistache::Rest::Request &request, Pistach
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -178,7 +178,7 @@ void UserApi::logout_user_handler(const Pistache::Rest::Request &request, Pistac
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand All @@ -200,7 +200,7 @@ void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistac
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
Expand Down
8 changes: 4 additions & 4 deletions samples/server/petstore/cpp-pistache/model/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool fromStringValue(const std::string &inStr, int32_t &value){
try {
value = std::stoi( inStr );
}
catch (const std::invalid_argument) {
catch (const std::invalid_argument&) {
return false;
}
return true;
Expand All @@ -60,7 +60,7 @@ bool fromStringValue(const std::string &inStr, int64_t &value){
try {
value = std::stol( inStr );
}
catch (const std::invalid_argument) {
catch (const std::invalid_argument&) {
return false;
}
return true;
Expand All @@ -76,7 +76,7 @@ bool fromStringValue(const std::string &inStr, float &value){
try {
value = std::stof( inStr );
}
catch (const std::invalid_argument) {
catch (const std::invalid_argument&) {
return false;
}
return true;
Expand All @@ -86,7 +86,7 @@ bool fromStringValue(const std::string &inStr, double &value){
try {
value = std::stod( inStr );
}
catch (const std::invalid_argument) {
catch (const std::invalid_argument&) {
return false;
}
return true;
Expand Down

0 comments on commit 68a5fa4

Please sign in to comment.