web_transport_error.h 1.8 KB

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