pdk_classy/grpc/
error.rs

1// Copyright (c) 2025, Salesforce, Inc.,
2// All rights reserved.
3// For full license text, see the LICENSE.txt file
4
5use std::error::Error;
6
7use crate::proxy_wasm::types::Status;
8
9use super::GrpcStatus;
10
11/// The Errors that may occur when processing a gRPC request before sending it to upstream.
12#[derive(Debug, thiserror::Error)]
13#[non_exhaustive]
14pub enum GrpcCallError {
15    /// Proxy status problem.
16    #[error(transparent)]
17    Proxy(#[from] GrpcProxyError),
18
19    /// Invalid upstream.
20    #[error("Invalid upstream '{0}'")]
21    InvalidUpstream(String),
22
23    /// Message encoding problem.
24    #[error(transparent)]
25    Encode(Box<dyn Error + Send + Sync>),
26}
27
28/// Proxy status problem.
29#[derive(Debug, thiserror::Error)]
30#[error("Proxy status problem: {0:?}")]
31pub struct GrpcProxyError(Status);
32
33impl GrpcProxyError {
34    pub(super) fn new(status: Status) -> Self {
35        Self(status)
36    }
37}
38
39/// The Errors that may occur when processing a gRPC request.
40#[derive(Debug, thiserror::Error)]
41#[non_exhaustive]
42pub enum GrpcClientError {
43    /// The Errors that may occur when processing a gRPC request before sending it to upstream.
44    #[error(transparent)]
45    Call(#[from] GrpcCallError),
46
47    /// Request awaited on create context event.
48    #[error("Request awaited on create context event")]
49    AwaitedOnCreateContext,
50
51    /// Response with empty content.
52    #[error("Empty content")]
53    EmptyContent,
54
55    /// Message decoding problem.
56    #[error(transparent)]
57    Decode(Box<dyn Error + Send + Sync>),
58
59    /// Bad gRPC status.
60    #[error("Bad gRPC status: {0}")]
61    Status(GrpcStatus),
62}