Update RTCError factory functions and a few usages.

Add optional message parameter to factory functions and implement
factories for all RTCErrorType values.

Update usages in candidate.cc, rtc_error_unittest.cc, and
data_channel_controller.cc to pass string directly.

Bug: none
Change-Id: I3650de52ecf3b1338b74ac3c93d41e5612f134c5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/466320
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Auto-Submit: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#47537}
diff --git a/api/candidate.cc b/api/candidate.cc
index 88cc225..ce93116 100644
--- a/api/candidate.cc
+++ b/api/candidate.cc
@@ -130,7 +130,7 @@
   } else if (line_end + 1 == message.size()) {
     first_line = message.substr(0, line_end);
   } else {
-    return RTCError::InvalidParameter() << "Expect one line only";
+    return RTCError::InvalidParameter("Expect one line only");
   }
 
   // For backwards compatibility, don't fail if the supplied string is in the
@@ -189,7 +189,7 @@
 
   std::optional<ProtocolType> protocol = StringToProto(transport);
   if (!protocol) {
-    return RTCError::InvalidParameter() << "Unsupported transport type";
+    return RTCError::InvalidParameter("Unsupported transport type");
   }
   bool tcp_protocol = false;
   switch (*protocol) {
@@ -201,7 +201,7 @@
       tcp_protocol = true;
       break;
     default:
-      return RTCError::InvalidParameter() << "Unsupported protocol";
+      return RTCError::InvalidParameter("Unsupported protocol");
   }
 
   IceCandidateType candidate_type;
@@ -215,7 +215,7 @@
   } else if (type == kCandidatePrflx) {
     candidate_type = IceCandidateType::kPrflx;
   } else {
-    return RTCError::InvalidParameter() << "Unsupported candidate type";
+    return RTCError::InvalidParameter("Unsupported candidate type");
   }
 
   size_t current_position = expected_min_fields;
diff --git a/api/rtc_error.h b/api/rtc_error.h
index a0a19ae..2742b58 100644
--- a/api/rtc_error.h
+++ b/api/rtc_error.h
@@ -144,20 +144,38 @@
   //
   // Preferred over the default constructor for code readability.
   static RTCError OK();
-  static RTCError InvalidParameter() {
-    return RTCError(RTCErrorType::INVALID_PARAMETER);
+  static RTCError InvalidParameter(absl::string_view message = "") {
+    return RTCError(RTCErrorType::INVALID_PARAMETER, message);
   }
-  static RTCError InvalidState() {
-    return RTCError(RTCErrorType::INVALID_STATE);
+  static RTCError InvalidState(absl::string_view message = "") {
+    return RTCError(RTCErrorType::INVALID_STATE, message);
   }
-  static RTCError InvalidModification() {
-    return RTCError(RTCErrorType::INVALID_MODIFICATION);
+  static RTCError InvalidModification(absl::string_view message = "") {
+    return RTCError(RTCErrorType::INVALID_MODIFICATION, message);
   }
-  static RTCError UnsupportedOperation() {
-    return RTCError(RTCErrorType::UNSUPPORTED_OPERATION);
+  static RTCError UnsupportedOperation(absl::string_view message = "") {
+    return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, message);
   }
-  static RTCError UnsupportedParameter() {
-    return RTCError(RTCErrorType::UNSUPPORTED_PARAMETER);
+  static RTCError UnsupportedParameter(absl::string_view message = "") {
+    return RTCError(RTCErrorType::UNSUPPORTED_PARAMETER, message);
+  }
+  static RTCError InvalidRange(absl::string_view message = "") {
+    return RTCError(RTCErrorType::INVALID_RANGE, message);
+  }
+  static RTCError SyntaxError(absl::string_view message = "") {
+    return RTCError(RTCErrorType::SYNTAX_ERROR, message);
+  }
+  static RTCError NetworkError(absl::string_view message = "") {
+    return RTCError(RTCErrorType::NETWORK_ERROR, message);
+  }
+  static RTCError ResourceExhausted(absl::string_view message = "") {
+    return RTCError(RTCErrorType::RESOURCE_EXHAUSTED, message);
+  }
+  static RTCError InternalError(absl::string_view message = "") {
+    return RTCError(RTCErrorType::INTERNAL_ERROR, message);
+  }
+  static RTCError OperationErrorWithData(absl::string_view message = "") {
+    return RTCError(RTCErrorType::OPERATION_ERROR_WITH_DATA, message);
   }
 
   // Error type.
diff --git a/api/rtc_error_unittest.cc b/api/rtc_error_unittest.cc
index 7527ae6..2267384 100644
--- a/api/rtc_error_unittest.cc
+++ b/api/rtc_error_unittest.cc
@@ -270,7 +270,7 @@
   } log_monitor;
 
   auto foo = [&]() {
-    return LOG_ERROR(RTCError::InvalidParameter() << "BuildStringLog");
+    return LOG_ERROR(RTCError::InvalidParameter("BuildStringLog"));
   };
 
   LogMessage::AddLogToStream(&log_monitor, LS_ERROR);
diff --git a/pc/data_channel_controller.cc b/pc/data_channel_controller.cc
index 8b42607..c8a4e1a 100644
--- a/pc/data_channel_controller.cc
+++ b/pc/data_channel_controller.cc
@@ -433,7 +433,7 @@
   RTC_DCHECK_RUN_ON(signaling_thread());
   RTC_DCHECK(!pc_->IsClosed());
   if (!config.IsValid()) {
-    return LOG_ERROR(RTCError::InvalidParameter() << "Invalid DataChannelInit");
+    return LOG_ERROR(RTCError::InvalidParameter("Invalid DataChannelInit"));
   }
 
   bool ready_to_send = false;