Give correct error code when SCTP is abruptly terminated.

Bug: chromium:1030631
Change-Id: I1890d6c7b30c06de1f4fdc6fe0cf1ff62ea4a63d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174830
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Taylor <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31293}
diff --git a/pc/data_channel.cc b/pc/data_channel.cc
index 4f871b4..0b9af37 100644
--- a/pc/data_channel.cc
+++ b/pc/data_channel.cc
@@ -370,10 +370,10 @@
   // The SctpTransport is unusable (for example, because the SCTP m= section
   // was rejected, or because the DTLS transport closed), so we need to close
   // abruptly.
-  // Note: this needs to differentiate between normal close and error close.
-  // https://w3c.github.io/webrtc-pc/#announcing-a-data-channel-as-closed
-  CloseAbruptlyWithError(
-      RTCError(RTCErrorType::NETWORK_ERROR, "Transport channel closed"));
+  RTCError error = RTCError(RTCErrorType::OPERATION_ERROR_WITH_DATA,
+                            "Transport channel closed");
+  error.set_error_detail(RTCErrorDetailType::SCTP_FAILURE);
+  CloseAbruptlyWithError(std::move(error));
 }
 
 // The remote peer request that this channel shall be closed.
diff --git a/pc/data_channel_unittest.cc b/pc/data_channel_unittest.cc
index 6bb8f7e..b29be33 100644
--- a/pc/data_channel_unittest.cc
+++ b/pc/data_channel_unittest.cc
@@ -630,9 +630,9 @@
   EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kClosed,
                  webrtc_data_channel_->state(), kDefaultTimeout);
   EXPECT_FALSE(webrtc_data_channel_->error().ok());
-  EXPECT_EQ(webrtc::RTCErrorType::NETWORK_ERROR,
+  EXPECT_EQ(webrtc::RTCErrorType::OPERATION_ERROR_WITH_DATA,
             webrtc_data_channel_->error().type());
-  EXPECT_EQ(webrtc::RTCErrorDetailType::NONE,
+  EXPECT_EQ(webrtc::RTCErrorDetailType::SCTP_FAILURE,
             webrtc_data_channel_->error().error_detail());
 }