From c64a5b8465cc2a4a0590b22cec215d8032dd2969 Mon Sep 17 00:00:00 2001 From: Dylan Brasseur Date: Fri, 28 Jul 2023 15:05:59 +0200 Subject: [PATCH] Catching exception --- .../source/Worker/ArmoniKWorker.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/cpp/ArmoniK.Api.Worker/source/Worker/ArmoniKWorker.cpp b/packages/cpp/ArmoniK.Api.Worker/source/Worker/ArmoniKWorker.cpp index e4f63642c..5a2c5be3c 100644 --- a/packages/cpp/ArmoniK.Api.Worker/source/Worker/ArmoniKWorker.cpp +++ b/packages/cpp/ArmoniK.Api.Worker/source/Worker/ArmoniKWorker.cpp @@ -59,20 +59,23 @@ Status API_WORKER_NAMESPACE::ArmoniKWorker::Process([[maybe_unused]] ::grpc::Ser TaskHandler task_handler(agent, iterator); task_handler.init(); + try { + ProcessStatus status = Execute(task_handler); - ProcessStatus status = Execute(task_handler); + logger_.debug("Finish call C++"); - logger_.debug("Finish call C++"); + armonik::api::grpc::v1::Output output; + if (status.ok()) { + *output.mutable_ok() = armonik::api::grpc::v1::Empty(); + } else { + output.mutable_error()->set_details(status.details()); + } - armonik::api::grpc::v1::Output output; - if (status.ok()) { - *output.mutable_ok() = armonik::api::grpc::v1::Empty(); - } else { - output.mutable_error()->set_details(status.details()); + *response->mutable_output() = output; + } catch (const std::exception &e) { + return {grpc::StatusCode::UNAVAILABLE, "Error processing task", e.what()}; } - *response->mutable_output() = output; - return grpc::Status::OK; }