Coverage Report

Created: 2023-11-12 09:30

/proc/self/cwd/source/extensions/filters/network/dubbo_proxy/app_exception.h
Line
Count
Source (jump to first uncovered line)
1
#pragma once
2
3
#include "envoy/common/exception.h"
4
5
#include "source/common/common/utility.h"
6
#include "source/extensions/filters/network/dubbo_proxy/filters/filter.h"
7
#include "source/extensions/filters/network/dubbo_proxy/metadata.h"
8
#include "source/extensions/filters/network/dubbo_proxy/protocol.h"
9
#include "source/extensions/filters/network/dubbo_proxy/serializer.h"
10
11
namespace Envoy {
12
namespace Extensions {
13
namespace NetworkFilters {
14
namespace DubboProxy {
15
16
using ResponseType = DubboFilters::DirectResponse::ResponseType;
17
18
template <typename T = ResponseStatus>
19
struct AppExceptionBase : public EnvoyException,
20
                          public DubboFilters::DirectResponse,
21
                          Logger::Loggable<Logger::Id::dubbo> {
22
  AppExceptionBase(const AppExceptionBase& ex) = default;
23
0
  AppExceptionBase(T status, const std::string& what) : EnvoyException(what), status_(status) {}
24
25
  ResponseType encode(MessageMetadata& metadata, DubboProxy::Protocol& protocol,
26
0
                      Buffer::Instance& buffer) const override {
27
0
    ASSERT(buffer.length() == 0);
28
29
0
    ENVOY_LOG(debug, "Exception information: {}", what());
30
31
0
    metadata.setResponseStatus<T>(status_);
32
0
    metadata.setMessageType(MessageType::Response);
33
0
    if (!protocol.encode(buffer, metadata, what(), response_type_)) {
34
0
      ExceptionUtil::throwEnvoyException("Failed to encode local reply message");
35
0
    }
36
37
0
    return ResponseType::Exception;
38
0
  }
39
40
  const T status_;
41
  const RpcResponseType response_type_{RpcResponseType::ResponseWithException};
42
};
43
44
using AppException = AppExceptionBase<>;
45
46
struct DownstreamConnectionCloseException : public EnvoyException {
47
  DownstreamConnectionCloseException(const std::string& what);
48
};
49
50
} // namespace DubboProxy
51
} // namespace NetworkFilters
52
} // namespace Extensions
53
} // namespace Envoy