@@ -799,13 +799,52 @@ ProtoServer::handle_request(
799799}
800800
801801std::vector<ProtoServerResp<std::string>>
802- ProtoServer::poll () {
802+ ProtoServer::poll (std:: uint32_t client_id ) {
803803 std::vector<ProtoServerResp<std::string>> out;
804- for (auto & resp : _poll ()) {
804+ try {
805+ const auto & responses = _poll ();
806+ for (const auto & resp : responses) {
807+ ProtoServerResp<std::string> str_resp;
808+ str_resp.data = resp.data .SerializeAsString ();
809+ str_resp.client_id = resp.client_id ;
810+ out.emplace_back (str_resp);
811+ }
812+
813+ } catch (const PerspectiveException& e) {
814+ proto::Response resp;
815+ auto * err = resp.mutable_server_error ()->mutable_message ();
816+ *err = std::string (e.what ());
817+ ProtoServerResp<std::string> str_resp;
818+ str_resp.data = resp.SerializeAsString ();
819+ str_resp.client_id = client_id;
820+ out.emplace_back (std::move (str_resp));
821+ } catch (const PerspectiveViewNotFoundException& e) {
822+ proto::Response resp;
823+ auto * err = resp.mutable_server_error ();
824+ err->set_status_code (proto::StatusCode::VIEW_NOT_FOUND );
825+ auto * msg = err->mutable_message ();
826+ *msg = std::string (e.what ());
827+ ProtoServerResp<std::string> str_resp;
828+ str_resp.data = resp.SerializeAsString ();
829+ str_resp.client_id = client_id;
830+ out.emplace_back (std::move (str_resp));
831+ } catch (const std::exception& e) {
832+ proto::Response resp;
833+ auto * err = resp.mutable_server_error ()->mutable_message ();
834+ *err = std::string (e.what ());
835+ ProtoServerResp<std::string> str_resp;
836+ str_resp.data = resp.SerializeAsString ();
837+ str_resp.client_id = client_id;
838+ out.emplace_back (std::move (str_resp));
839+ } catch (...) {
840+ proto::Response resp;
841+ auto * err = resp.mutable_server_error ()->mutable_message ();
842+ std::exception_ptr p = std::current_exception ();
843+ *err = " Unknown exception" ;
805844 ProtoServerResp<std::string> str_resp;
806- str_resp.data = resp.data . SerializeAsString ();
807- str_resp.client_id = resp. client_id ;
808- out.emplace_back (str_resp);
845+ str_resp.data = resp.SerializeAsString ();
846+ str_resp.client_id = client_id;
847+ out.emplace_back (std::move ( str_resp) );
809848 }
810849
811850 return out;
@@ -2141,11 +2180,11 @@ ProtoServer::_handle_request(std::uint32_t client_id, Request&& req) {
21412180 auto tm = scalar.get <t_date>();
21422181 std::stringstream ss;
21432182 ss << std::setfill (' 0' ) << std::setw (4 ) << tm.year ()
2144- << " -" << std::setfill (' 0' ) << std::setw (2 )
2145- // Increment month by 1, as date::month is [1-12] but
2146- // t_date::month() is [0-11]
2147- << tm.month () + 1
21482183 << " -" << std::setfill (' 0' )
2184+ << std::setw (2 )
2185+ // Increment month by 1, as date::month is [1-12]
2186+ // but t_date::month() is [0-11]
2187+ << tm.month () + 1 << " -" << std::setfill (' 0' )
21492188 << std::setw (2 ) << tm.day ();
21502189 s->set_string (ss.str ());
21512190 break ;
0 commit comments