CRef<CGCClient_AssembliesForSequences> CGenomicCollectionsService::FindAssembliesBySequences(const list<string>& sequence_acc, int filter, CGCClient_GetAssemblyBySequenceRequest::ESort sort, bool top_only) { CGCClient_GetAssemblyBySequenceRequest req; CGCClientResponse reply; for(auto acc : sequence_acc) if(acc.length() > 30) { NCBI_THROW(CException, eUnknown, "Accession is longer than 30 characters: " + acc); } req.SetSequence_acc().assign(sequence_acc.begin(), sequence_acc.end()); req.SetFilter(filter); req.SetSort(sort); req.SetTop_assembly_only(top_only ? 1 : 0); LogRequest(req); try { CRef<CGCClient_AssembliesForSequences> assm = AskGet_assembly_by_sequence(req, &reply); return assm; } catch (const CException& ex) { if(reply.IsSrvr_error()) { NCBI_REPORT_EXCEPTION(reply.GetSrvr_error().GetDescription(), ex); } throw; } return CRef<CGCClient_AssembliesForSequences>(); }
CRef<CGCClient_AssemblySequenceInfo> CGenomicCollectionsService::FindBestAssembly(const list<string>& seq_id, int filter_type, int sort_type) { CGCClient_FindBestAssemblyRequest req; CGCClientResponse reply; req.SetSeq_id_acc().assign(seq_id.begin(), seq_id.end()); req.SetFilter(filter_type); req.SetSort(sort_type); req.SetAssembly_return_limit(1); LogRequest(req); try { CRef<CGCClient_AssembliesForSequences> assm = AskGet_best_assembly(req, &reply); return assm->CanGetAssemblies() && !assm->GetAssemblies().empty() ? CRef<CGCClient_AssemblySequenceInfo>(assm->SetAssemblies().front()) : CRef<CGCClient_AssemblySequenceInfo>(); } catch (const CException& ex) { if(reply.IsSrvr_error()) { NCBI_REPORT_EXCEPTION(reply.GetSrvr_error().GetDescription().c_str(), ex); } throw; } }
int CNetCacheBlobFetchApp::OnException(std::exception& e, CNcbiOstream& os) { union { CArgException* arg_exception; CNetCacheException* nc_exception; }; string status_str; string message; if ((arg_exception = dynamic_cast<CArgException*>(&e)) != NULL) { status_str = "400 Bad Request"; message = arg_exception->GetMsg(); SetHTTPStatus(CRequestStatus::e400_BadRequest); } else if ((nc_exception = dynamic_cast<CNetCacheException*>(&e)) != NULL) { switch (nc_exception->GetErrCode()) { case CNetCacheException::eAccessDenied: status_str = "403 Forbidden"; message = nc_exception->GetMsg(); SetHTTPStatus(CRequestStatus::e403_Forbidden); break; case CNetCacheException::eBlobNotFound: status_str = "404 Not Found"; message = nc_exception->GetMsg(); SetHTTPStatus(CRequestStatus::e404_NotFound); break; default: return CCgiApplication::OnException(e, os); } } else return CCgiApplication::OnException(e, os); // Don't try to write to a broken output if (!os.good()) { return -1; } try { // HTTP header os << "Status: " << status_str << HTTP_EOL << "Content-Type: text/plain" HTTP_EOL HTTP_EOL << "ERROR: " << status_str << " " HTTP_EOL HTTP_EOL << message << HTTP_EOL; // Check for problems in sending the response if (!os.good()) { ERR_POST("CNetCacheBlobFetchApp::OnException() " "failed to send error page back to the client"); return -1; } } catch (exception& e) { NCBI_REPORT_EXCEPTION("(CGI) CNetCacheBlobFetchApp::OnException", e); } return 0; }
CTMS_CreateUserTrack_Client::TReplyRef CTMS_CreateUserTrack_Client::Fetch(const TRequest& request) const { CRef<TReply> reply; try { reply.Reset(new TReply()); TBaseClient::Ask(request, *reply); } catch (const CException& e) { NCBI_REPORT_EXCEPTION("Exception communicating with TMS-CreateUserTrack service ", e); reply.Reset(); } return reply; }
CRef<CGCClient_EquivalentAssemblies> CGenomicCollectionsService::GetEquivalentAssemblies(const string& acc, int equivalency) { CGCClient_GetEquivalentAssembliesRequest req; CGCClientResponse reply; req.SetAccession(acc); req.SetEquivalency(equivalency); LogRequest(req); try { CRef<CGCClient_EquivalentAssemblies> assm = AskGet_equivalent_assemblies(req, &reply); return assm; } catch (const CException& ex) { if(reply.IsSrvr_error()) { NCBI_REPORT_EXCEPTION(reply.GetSrvr_error().GetDescription(), ex); } throw; } }
void CTestDiagApp::x_PrintMessages(int test_number, int idx, const char* module, const char* nclass, const char* function) { string location = string(module) + "::" + nclass + "::" + function + "()"; string postmsg = location + " in ERR_POST"; string exceptmsg = location + " in the one level exception"; string secondmsg = location + " in the two levels exception"; if (idx == 0) { m_Messages[ TCase( test_number, 0 ) ] = postmsg; m_Messages[ TCase( test_number, 1 ) ] = exceptmsg; m_Messages[ TCase( test_number, 2 ) ] = secondmsg; } // ERR_POST ERR_POST(x_MakeMessage(postmsg, idx, TCase(test_number,0)) << MDiagModule(module) << MDiagClass(nclass) << MDiagFunction(function)); // one level exception try { NCBI_EXCEPTION_VAR(expt, CException, eUnknown, "exception"); expt.SetModule(module); expt.SetClass(nclass); expt.SetFunction(function); NCBI_EXCEPTION_THROW(expt); } catch (const CException& ex) { NCBI_REPORT_EXCEPTION(x_MakeMessage(exceptmsg, idx, TCase(test_number, 1)), ex); } #if defined(NCBI_COMPILER_WORKSHOP) # if NCBI_COMPILER_VERSION == 530 || NCBI_COMPILER_VERSION == 550 // Workshop 5.3 and 5.5 have MT-unsafe throw. To avoid test failures // use mutex. DEFINE_STATIC_FAST_MUTEX(s_ThrowMutex); CFastMutexGuard guard(s_ThrowMutex); # endif #endif // two level exceptions try { try { NCBI_EXCEPTION_VAR(expt, CException, eUnknown, "exception1"); expt.SetModule(module); expt.SetClass(nclass); expt.SetFunction(function); NCBI_EXCEPTION_THROW(expt); } catch (const CException& ex) { NCBI_EXCEPTION_VAR_EX(e2, &ex, CException, eUnknown, "exception2"); e2.SetModule(module); e2.SetClass(nclass); e2.SetFunction(function); NCBI_EXCEPTION_THROW(e2); } } catch (const CException& ex) { NCBI_REPORT_EXCEPTION(x_MakeMessage(secondmsg, idx, TCase(test_number, 2)), ex); } }