@@ -283,22 +283,30 @@ void ComputeThread::on_message(websocketpp::connection_hdl hdl, message_ptr msg)
283283 root=nlohmann::json::parse (msg->get_payload ());
284284 }
285285 catch (nlohmann::json::exception& e) {
286- std::cerr << " cadabra-client: cannot parse message" << std::endl;
286+ std::cerr << " cadabra-client: cannot parse message." << std::endl;
287+ return ;
288+ }
289+ if (root.count (" header" )==0 ) {
290+ std::cerr << " cadabra-client: received message without 'header'." << std::endl;
291+ return ;
292+ }
293+ if (root.count (" content" )==0 ) {
294+ std::cerr << " cadabra-client: received message without 'content'." << std::endl;
287295 return ;
288296 }
289297 const nlohmann::json& header = root[" header" ];
290298 const nlohmann::json& content = root[" content" ];
291299 const std::string msg_type = root.value (" msg_type" , " " );
292300
293301 DataCell::id_t parent_id;
294- parent_id.id = header[ " parent_id" ]. get < uint64_t >( );
302+ parent_id.id = header. value ( " parent_id" , uint64_t ( 0 ) );
295303 if (header.value (" parent_origin" , " " )==" client" )
296304 parent_id.created_by_client =true ;
297305 else
298306 parent_id.created_by_client =false ;
299307 DataCell::id_t cell_id;
300308 cell_id.id = header[" cell_id" ].get <uint64_t >();
301- if (header[ " cell_origin" ]. get <std::string>( )==" client" )
309+ if (header. value ( " cell_origin" , " " )==" client" )
302310 cell_id.created_by_client =true ;
303311 else
304312 cell_id.created_by_client =false ;
0 commit comments