userver: userver/ugrpc/status_codes.hpp Source File
Loading...
Searching...
No Matches
status_codes.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/ugrpc/status_codes.hpp
4/// @brief Utilities for grpc::StatusCode
5
6#include <grpcpp/support/status.h>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace ugrpc {
11
12/// @brief Convert string to grpc::StatusCode
13/// @throws std::runtime_error
14grpc::StatusCode StatusCodeFromString(std::string_view str);
15
16/// @brief Convert grpc::StatusCode to string
18
19/// @brief Whether a given status code is definitely a server-side error
20///
21/// Currently includes:
22///
23/// * `UNKNOWN`
24/// * `UNIMPLEMENTED`
25/// * `INTERNAL`
26/// * `UNAVAILABLE`
27/// * `DATA_LOSS`
28///
29/// We intentionally do not include `CANCELLED` and `DEADLINE_EXPIRED` here, because the situation may either be
30/// considered not erroneous at all (when a client explicitly cancels an RPC; when a client attempts an RPC with a very
31/// short deadline), or there is no single obvious service to blame (when the collective deadline expires for an RPC
32/// tree).
33bool IsServerError(grpc::StatusCode code) noexcept;
34
35} // namespace ugrpc
36
37USERVER_NAMESPACE_END