xref: /aosp_15_r20/external/cronet/net/quic/web_transport_error.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_QUIC_WEB_TRANSPORT_ERROR_H_
6 #define NET_QUIC_WEB_TRANSPORT_ERROR_H_
7 
8 #include <ostream>
9 #include <string>
10 #include <string_view>
11 
12 #include "net/base/net_errors.h"
13 #include "net/base/net_export.h"
14 #include "net/third_party/quiche/src/quiche/quic/core/quic_error_codes.h"
15 
16 namespace net {
17 
18 struct NET_EXPORT WebTransportError {
19   WebTransportError() = default;
WebTransportErrorWebTransportError20   explicit WebTransportError(int net_error) : net_error(net_error) {
21     DCHECK_LT(net_error, 0);
22   }
WebTransportErrorWebTransportError23   WebTransportError(int net_error,
24                     quic::QuicErrorCode quic_error,
25                     std::string_view details,
26                     bool safe_to_report_details)
27       : net_error(net_error),
28         quic_error(quic_error),
29         details(details),
30         safe_to_report_details(safe_to_report_details) {
31     DCHECK_LT(net_error, 0);
32   }
33 
34   // |net_error| is always set to a meaningful value.
35   int net_error = ERR_FAILED;
36 
37   // |quic_error| is set to a QUIC error, or to quic::QUIC_NO_ERROR if the error
38   // originates non-QUIC parts of the stack.
39   quic::QuicErrorCode quic_error = quic::QUIC_NO_ERROR;
40 
41   // Human-readable error summary.
42   std::string details;
43 
44   // WebTransport requires that the connection errors have to be
45   // undistinguishable until the peer is confirmed to be a WebTransport
46   // endpoint.  See https://w3c.github.io/webtransport/#protocol-security
47   bool safe_to_report_details = false;
48 };
49 
50 NET_EXPORT
51 std::string WebTransportErrorToString(const WebTransportError& error);
52 
53 NET_EXPORT
54 std::ostream& operator<<(std::ostream& os, const WebTransportError& error);
55 
56 }  // namespace net
57 
58 #endif  // NET_QUIC_WEB_TRANSPORT_ERROR_H_
59