• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

getdozer / dozer / 4283961027

pending completion
4283961027

push

github

GitHub
feat: Blue green cache (#1061)

645 of 645 new or added lines in 45 files covered. (100.0%)

27779 of 39307 relevant lines covered (70.67%)

52489.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/dozer-api/src/errors.rs
1
#![allow(clippy::enum_variant_names)]
2
use std::path::PathBuf;
3

4
use actix_web::http::header::ContentType;
5
use actix_web::http::StatusCode;
6
use actix_web::HttpResponse;
7
use dozer_types::thiserror::Error;
8
use dozer_types::{serde_json, thiserror};
9

10
use dozer_cache::errors::CacheError;
11
use dozer_types::errors::internal::BoxedError;
12
use dozer_types::errors::types::TypeError;
13
use prost_reflect::{DescriptorError, Kind};
14

15
#[derive(Error, Debug)]
×
16
pub enum ApiError {
17
    #[error(transparent)]
18
    ApiAuthError(#[from] AuthError),
19
    #[error("Failed to generate openapi documentation")]
20
    ApiGenerationError(#[source] GenerationError),
21
    #[error("Failed to open cache: {0}")]
22
    OpenCache(#[source] CacheError),
23
    #[error("Failed to open cache: {0}")]
24
    CacheNotFound(String),
25
    #[error("Cannot find schema by name")]
26
    SchemaNotFound(#[source] CacheError),
27
    #[error("Get by primary key is not supported when it is composite: {0:?}")]
28
    MultiIndexFetch(String),
29
    #[error("Document not found")]
30
    NotFound(#[source] CacheError),
31
    #[error("Failed to count records")]
32
    CountFailed(#[source] CacheError),
33
    #[error("Failed to query cache")]
34
    QueryFailed(#[source] CacheError),
35
    #[error(transparent)]
36
    InternalError(#[from] BoxedError),
37
    #[error(transparent)]
38
    TypeError(#[from] TypeError),
39
    #[error(transparent)]
40
    PortAlreadyInUse(#[from] std::io::Error),
41
}
42

43
impl ApiError {
44
    pub fn map_serialization_error(e: serde_json::Error) -> ApiError {
×
45
        ApiError::TypeError(TypeError::SerializationError(
×
46
            dozer_types::errors::types::SerializationError::Json(e),
×
47
        ))
×
48
    }
×
49
    pub fn map_deserialization_error(e: serde_json::Error) -> ApiError {
×
50
        ApiError::TypeError(TypeError::DeserializationError(
×
51
            dozer_types::errors::types::DeserializationError::Json(e),
×
52
        ))
×
53
    }
×
54
}
55

56
#[derive(Error, Debug)]
×
57
pub enum GrpcError {
58
    #[error("Internal gRPC server error: {0}")]
59
    InternalError(#[from] BoxedError),
60
    #[error("Cannot send to broadcast channel")]
61
    CannotSendToBroadcastChannel,
62
    #[error(transparent)]
63
    SerizalizeError(#[from] serde_json::Error),
64
    #[error("Missing primary key to query by id: {0}")]
65
    MissingPrimaryKeyToQueryById(String),
66
    #[error(transparent)]
67
    GenerationError(#[from] GenerationError),
68
    #[error(transparent)]
69
    SchemaNotFound(#[from] CacheError),
70
    #[error("{1}: Schema for endpoint: {0} not found")]
71
    SchemaNotInitialized(String, #[source] CacheError),
72
    #[error(transparent)]
73
    ServerReflectionError(#[from] tonic_reflection::server::Error),
74
    #[error("Unable to decode query expression: {0}")]
75
    UnableToDecodeQueryExpression(String),
76
    #[error("{0}")]
77
    TransportErrorDetail(String),
78
}
79
impl From<GrpcError> for tonic::Status {
×
80
    fn from(input: GrpcError) -> Self {
×
81
        tonic::Status::new(tonic::Code::Internal, input.to_string())
×
82
    }
×
83
}
84

85
impl From<ApiError> for tonic::Status {
×
86
    fn from(input: ApiError) -> Self {
×
87
        tonic::Status::new(tonic::Code::Unknown, input.to_string())
×
88
    }
×
89
}
90

×
91
#[derive(Error, Debug)]
×
92
pub enum GenerationError {
93
    #[error(transparent)]
94
    InternalError(#[from] BoxedError),
95
    #[error("directory path {0:?} does not exist")]
96
    DirPathNotExist(PathBuf),
97
    #[error("DozerType to Proto type not supported: {0}")]
98
    DozerToProtoTypeNotSupported(String),
99
    #[error("Missing primary key to query by id: {0}")]
100
    MissingPrimaryKeyToQueryById(String),
101
    #[error("Cannot read proto descriptor: {0}")]
102
    ProtoDescriptorError(#[source] DescriptorError),
103
    #[error("Service not found: {0}")]
104
    ServiceNotFound(String),
105
    #[error("Field not found: {field_name} in message: {message_name}")]
106
    FieldNotFound {
107
        message_name: String,
108
        field_name: String,
109
    },
110
    #[error("Expected message field: {filed_name}, but found: {actual:?}")]
111
    ExpectedMessageField { filed_name: String, actual: Kind },
112
    #[error("Unexpected method {0}")]
113
    UnexpectedMethod(String),
114
    #[error("Missing count method for: {0}")]
115
    MissingCountMethod(String),
116
    #[error("Missing query method for: {0}")]
117
    MissingQueryMethod(String),
118
}
119

×
120
#[derive(Error, Debug)]
×
121
pub enum AuthError {
122
    #[error("Cannot access this route.")]
123
    Unauthorized,
124
    #[error("Invalid token provided")]
125
    InvalidToken,
126
    #[error("Issuer is invalid")]
127
    InvalidIssuer,
128
    #[error(transparent)]
129
    InternalError(#[from] BoxedError),
130
}
131

132
impl actix_web::error::ResponseError for ApiError {
×
133
    fn error_response(&self) -> HttpResponse {
×
134
        HttpResponse::build(self.status_code())
×
135
            .insert_header(ContentType::json())
×
136
            .body(self.to_string())
×
137
    }
×
138

×
139
    fn status_code(&self) -> StatusCode {
×
140
        match *self {
×
141
            ApiError::TypeError(_) => StatusCode::BAD_REQUEST,
×
142
            ApiError::ApiAuthError(_) => StatusCode::UNAUTHORIZED,
×
143
            ApiError::NotFound(_) => StatusCode::NOT_FOUND,
×
144
            ApiError::ApiGenerationError(_)
145
            | ApiError::SchemaNotFound(_)
×
146
            | ApiError::MultiIndexFetch(_) => StatusCode::UNPROCESSABLE_ENTITY,
×
147
            ApiError::InternalError(_)
148
            | ApiError::OpenCache(_)
149
            | ApiError::CacheNotFound(_)
150
            | ApiError::QueryFailed(_)
151
            | ApiError::CountFailed(_)
×
152
            | ApiError::PortAlreadyInUse(_) => StatusCode::INTERNAL_SERVER_ERROR,
×
153
        }
×
154
    }
×
155
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc