userver: userver/ugrpc/server/exceptions.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
exceptions.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/ugrpc/server/exceptions.hpp
4/// @brief Errors thrown by gRPC server streams
5
6#include <exception>
7#include <string>
8#include <string_view>
9
10#include <grpcpp/support/status.h>
11#include <grpcpp/support/status_code_enum.h>
12
13USERVER_NAMESPACE_BEGIN
14
15/// Server-side utilities
16namespace ugrpc::server {
17
18/// @brief Base exception for all the server errors
19class BaseError : public std::exception {
20public:
21 explicit BaseError(std::string message);
22
23 const char* what() const noexcept override;
24
25private:
26 std::string message_;
27};
28
29/// @brief Error during an RPC
30class RpcError : public BaseError {
31public:
32 RpcError(std::string_view call_name, std::string_view additional_info);
33};
34
35/// @brief RPC failed without a status. This means that either the call got
36/// cancelled using `TryCancel`, the deadline has expired, or the client
37/// disconnected.
39public:
40 RpcInterruptedError(std::string_view call_name, std::string_view stage);
41};
42
43/// @brief Users can throw ErrorWithStatus in their
44/// RPC's implementation to return provided status code as a result.
45class ErrorWithStatus : public BaseError {
46public:
47 explicit ErrorWithStatus(grpc::Status status);
48
49 ErrorWithStatus(grpc::StatusCode status_code, std::string message);
50
51 const grpc::Status& GetStatus() const;
52
53 grpc::Status&& ExtractStatus();
54
55private:
56 grpc::Status status_;
57};
58
59} // namespace ugrpc::server
60
61USERVER_NAMESPACE_END