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

getdozer / dozer / 4295401807

pending completion
4295401807

push

github

GitHub
Bump version (#1099)

28685 of 39545 relevant lines covered (72.54%)

52105.29 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 there is no primary key")]
28
    NoPrimaryKey,
29
    #[error("Get by primary key is not supported when it is composite: {0:?}")]
30
    MultiIndexFetch(String),
31
    #[error("Document not found")]
32
    NotFound(#[source] CacheError),
33
    #[error("Failed to count records")]
34
    CountFailed(#[source] CacheError),
35
    #[error("Failed to query cache")]
36
    QueryFailed(#[source] CacheError),
37
    #[error(transparent)]
38
    InternalError(#[from] BoxedError),
39
    #[error(transparent)]
40
    TypeError(#[from] TypeError),
41
    #[error(transparent)]
42
    PortAlreadyInUse(#[from] std::io::Error),
43
}
44

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

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

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

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

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

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

×
141
    fn status_code(&self) -> StatusCode {
×
142
        match *self {
×
143
            ApiError::TypeError(_) => StatusCode::BAD_REQUEST,
×
144
            ApiError::ApiAuthError(_) => StatusCode::UNAUTHORIZED,
×
145
            ApiError::NotFound(_) => StatusCode::NOT_FOUND,
×
146
            ApiError::ApiGenerationError(_)
×
147
            | ApiError::SchemaNotFound(_)
148
            | ApiError::NoPrimaryKey
149
            | ApiError::MultiIndexFetch(_) => StatusCode::UNPROCESSABLE_ENTITY,
×
150
            ApiError::InternalError(_)
151
            | ApiError::OpenCache(_)
152
            | ApiError::CacheNotFound(_)
×
153
            | ApiError::QueryFailed(_)
154
            | ApiError::CountFailed(_)
×
155
            | ApiError::PortAlreadyInUse(_) => StatusCode::INTERNAL_SERVER_ERROR,
×
156
        }
157
    }
×
158
}
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