From b916a70c9df353ca96dc87c75dee96223950cf89 Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Mon, 18 Sep 2023 13:06:24 +0200 Subject: [PATCH] Use RTCError instead of string for PostCreateSessionDescriptionFailed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit which allows exposing more granular errors from CreateOffer/CreateAnswer BUG=webrtc:15499 Change-Id: If72a84515e220d1e7ca739318bf0b6e8a662f60e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/320600 Reviewed-by: Henrik Boström Reviewed-by: Harald Alvestrand Commit-Queue: Philipp Hancke Cr-Commit-Position: refs/heads/main@{#40763} --- pc/webrtc_session_description_factory.cc | 52 ++++++++++++------------ pc/webrtc_session_description_factory.h | 2 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/pc/webrtc_session_description_factory.cc b/pc/webrtc_session_description_factory.cc index 3d398e3b6e..05cbe47aef 100644 --- a/pc/webrtc_session_description_factory.cc +++ b/pc/webrtc_session_description_factory.cc @@ -194,15 +194,15 @@ void WebRtcSessionDescriptionFactory::CreateOffer( std::string error = "CreateOffer"; if (certificate_request_state_ == CERTIFICATE_FAILED) { error += kFailedDueToIdentityFailed; - RTC_LOG(LS_ERROR) << error; - PostCreateSessionDescriptionFailed(observer, error); + PostCreateSessionDescriptionFailed( + observer, RTCError(RTCErrorType::INTERNAL_ERROR, std::move(error))); return; } if (!ValidMediaSessionOptions(session_options)) { error += " called with invalid session options"; - RTC_LOG(LS_ERROR) << error; - PostCreateSessionDescriptionFailed(observer, error); + PostCreateSessionDescriptionFailed( + observer, RTCError(RTCErrorType::INTERNAL_ERROR, std::move(error))); return; } @@ -223,27 +223,27 @@ void WebRtcSessionDescriptionFactory::CreateAnswer( std::string error = "CreateAnswer"; if (certificate_request_state_ == CERTIFICATE_FAILED) { error += kFailedDueToIdentityFailed; - RTC_LOG(LS_ERROR) << error; - PostCreateSessionDescriptionFailed(observer, error); + PostCreateSessionDescriptionFailed( + observer, RTCError(RTCErrorType::INTERNAL_ERROR, std::move(error))); return; } if (!sdp_info_->remote_description()) { error += " can't be called before SetRemoteDescription."; - RTC_LOG(LS_ERROR) << error; - PostCreateSessionDescriptionFailed(observer, error); + PostCreateSessionDescriptionFailed( + observer, RTCError(RTCErrorType::INTERNAL_ERROR, std::move(error))); return; } if (sdp_info_->remote_description()->GetType() != SdpType::kOffer) { error += " failed because remote_description is not an offer."; - RTC_LOG(LS_ERROR) << error; - PostCreateSessionDescriptionFailed(observer, error); + PostCreateSessionDescriptionFailed( + observer, RTCError(RTCErrorType::INTERNAL_ERROR, std::move(error))); return; } if (!ValidMediaSessionOptions(session_options)) { error += " called with invalid session options."; - RTC_LOG(LS_ERROR) << error; - PostCreateSessionDescriptionFailed(observer, error); + PostCreateSessionDescriptionFailed( + observer, RTCError(RTCErrorType::INTERNAL_ERROR, std::move(error))); return; } @@ -286,8 +286,9 @@ void WebRtcSessionDescriptionFactory::InternalCreateOffer( ? sdp_info_->local_description()->description() : nullptr); if (!desc) { - PostCreateSessionDescriptionFailed(request.observer.get(), - "Failed to initialize the offer."); + PostCreateSessionDescriptionFailed( + request.observer.get(), RTCError(RTCErrorType::INTERNAL_ERROR, + "Failed to initialize the offer.")); return; } @@ -348,8 +349,9 @@ void WebRtcSessionDescriptionFactory::InternalCreateAnswer( ? sdp_info_->local_description()->description() : nullptr); if (!desc) { - PostCreateSessionDescriptionFailed(request.observer.get(), - "Failed to initialize the answer."); + PostCreateSessionDescriptionFailed( + request.observer.get(), RTCError(RTCErrorType::INTERNAL_ERROR, + "Failed to initialize the answer.")); return; } @@ -387,24 +389,22 @@ void WebRtcSessionDescriptionFactory::FailPendingRequests( create_session_description_requests_.front(); PostCreateSessionDescriptionFailed( request.observer.get(), - ((request.type == CreateSessionDescriptionRequest::kOffer) - ? "CreateOffer" - : "CreateAnswer") + - reason); + RTCError(RTCErrorType::INTERNAL_ERROR, + ((request.type == CreateSessionDescriptionRequest::kOffer) + ? "CreateOffer" + : "CreateAnswer") + + reason)); create_session_description_requests_.pop(); } } void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionFailed( CreateSessionDescriptionObserver* observer, - const std::string& error) { + RTCError error) { Post([observer = rtc::scoped_refptr(observer), - error]() mutable { - observer->OnFailure( - RTCError(RTCErrorType::INTERNAL_ERROR, std::move(error))); - }); - RTC_LOG(LS_ERROR) << "Create SDP failed: " << error; + error]() mutable { observer->OnFailure(error); }); + RTC_LOG(LS_ERROR) << "CreateSessionDescription failed: " << error.message(); } void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionSucceeded( diff --git a/pc/webrtc_session_description_factory.h b/pc/webrtc_session_description_factory.h index 122a720162..22ead41d9b 100644 --- a/pc/webrtc_session_description_factory.h +++ b/pc/webrtc_session_description_factory.h @@ -119,7 +119,7 @@ class WebRtcSessionDescriptionFactory { void FailPendingRequests(const std::string& reason); void PostCreateSessionDescriptionFailed( CreateSessionDescriptionObserver* observer, - const std::string& error); + RTCError error); void PostCreateSessionDescriptionSucceeded( CreateSessionDescriptionObserver* observer, std::unique_ptr description);