Use RTCError instead of string for PostCreateSessionDescriptionFailed
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 <hbos@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Philipp Hancke <phancke@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#40763}
diff --git a/pc/webrtc_session_description_factory.cc b/pc/webrtc_session_description_factory.cc
index 3d398e3..05cbe47 100644
--- a/pc/webrtc_session_description_factory.cc
+++ b/pc/webrtc_session_description_factory.cc
@@ -194,15 +194,15 @@
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 @@
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 @@
? 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 @@
? 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 @@
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<CreateSessionDescriptionObserver>(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 122a7201..22ead41 100644
--- a/pc/webrtc_session_description_factory.h
+++ b/pc/webrtc_session_description_factory.h
@@ -119,7 +119,7 @@
void FailPendingRequests(const std::string& reason);
void PostCreateSessionDescriptionFailed(
CreateSessionDescriptionObserver* observer,
- const std::string& error);
+ RTCError error);
void PostCreateSessionDescriptionSucceeded(
CreateSessionDescriptionObserver* observer,
std::unique_ptr<SessionDescriptionInterface> description);