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

getdozer / dozer / 4062405381

pending completion
4062405381

Pull #776

github

GitHub
Merge c50dcefa1 into a81d03c98
Pull Request #776: fix: `ApiEndpoint` is not serializing all fields

5 of 5 new or added lines in 1 file covered. (100.0%)

24316 of 37369 relevant lines covered (65.07%)

35801.41 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 actix_web::http::header::ContentType;
3
use actix_web::http::StatusCode;
4
use actix_web::HttpResponse;
5
use dozer_types::thiserror::Error;
6
use dozer_types::{serde_json, thiserror};
7

8
use dozer_cache::errors::{CacheError, QueryValidationError};
9
use dozer_types::errors::internal::BoxedError;
10
use dozer_types::errors::types::TypeError;
11
use prost_reflect::DescriptorError;
12

13
#[derive(Error, Debug)]
×
14
pub enum ApiError {
15
    #[error("Invalid query provided")]
16
    InvalidQuery(#[source] QueryValidationError),
17
    #[error(transparent)]
18
    ApiAuthError(#[from] AuthError),
19
    #[error("Failed to generate openapi documentation")]
20
    ApiGenerationError(#[source] GenerationError),
21
    #[error("Cannot find schema by name")]
22
    SchemaNotFound(#[source] CacheError),
23
    #[error("Document not found")]
24
    NotFound(#[source] CacheError),
25
    #[error(transparent)]
26
    InternalError(#[from] BoxedError),
27
    #[error(transparent)]
28
    InitError(#[from] InitError),
29
    #[error(transparent)]
30
    TypeError(#[from] TypeError),
31
    #[error("Schema Identifier is not present")]
32
    SchemaIdentifierNotFound,
33
    #[error(transparent)]
34
    PortAlreadyInUse(#[from] std::io::Error),
35
}
36

37
impl ApiError {
38
    pub fn map_serialization_error(e: serde_json::Error) -> ApiError {
×
39
        ApiError::TypeError(TypeError::SerializationError(
×
40
            dozer_types::errors::types::SerializationError::Json(e),
×
41
        ))
×
42
    }
×
43
    pub fn map_deserialization_error(e: serde_json::Error) -> ApiError {
×
44
        ApiError::TypeError(TypeError::DeserializationError(
×
45
            dozer_types::errors::types::DeserializationError::Json(e),
×
46
        ))
×
47
    }
×
48
}
49

50
#[derive(Error, Debug)]
×
51
pub enum GRPCError {
52
    #[error("Internal GRPC server error: {0}")]
53
    InternalError(#[from] BoxedError),
54

55
    #[error(transparent)]
56
    SerizalizeError(#[from] serde_json::Error),
57
    #[error("Missing primary key to query by id: {0}")]
58
    MissingPrimaryKeyToQueryById(String),
59
    #[error(transparent)]
60
    GenerationError(#[from] GenerationError),
61
    #[error(transparent)]
62
    SchemaNotFound(#[from] CacheError),
63
    #[error("{1}: Schema for endpoint: {0} not found")]
64
    SchemaNotInitialized(String, #[source] CacheError),
65
    #[error(transparent)]
66
    ServerReflectionError(#[from] tonic_reflection::server::Error),
67
    #[error("Unable to decode query expression: {0}")]
68
    UnableToDecodeQueryExpression(String),
69
    #[error("{0}")]
70
    TransportErrorDetail(String),
71
}
72
impl From<GRPCError> for tonic::Status {
73
    fn from(input: GRPCError) -> Self {
×
74
        tonic::Status::new(tonic::Code::Internal, input.to_string())
×
75
    }
×
76
}
77

78
impl From<ApiError> for tonic::Status {
79
    fn from(input: ApiError) -> Self {
×
80
        tonic::Status::new(tonic::Code::Unknown, input.to_string())
×
81
    }
×
82
}
83

84
#[derive(Error, Debug)]
×
85
pub enum InitError {
86
    #[error("pipeline_details not initialized")]
87
    PipelineNotInitialized,
88
    #[error("api_security not initialized")]
89
    SecurityNotInitialized,
90
}
91

92
#[derive(Error, Debug)]
×
93
pub enum GenerationError {
94
    #[error(transparent)]
95
    InternalError(#[from] BoxedError),
96
    #[error("directory path does not exist")]
97
    DirPathNotExist,
98
    #[error("DozerType to Proto type not supported: {0}")]
99
    DozerToProtoTypeNotSupported(String),
100
    #[error("Missing primary key to query by id: {0}")]
101
    MissingPrimaryKeyToQueryById(String),
102
    #[error("Cannot read proto descriptor: {0}")]
103
    ProtoDescriptorError(#[source] DescriptorError),
104
}
105

106
#[derive(Error, Debug)]
×
107
pub enum AuthError {
108
    #[error("Cannot access this route.")]
109
    Unauthorized,
110
    #[error("Invalid token provided")]
111
    InvalidToken,
112
    #[error("Issuer is invalid")]
113
    InvalidIssuer,
114
    #[error(transparent)]
115
    InternalError(#[from] BoxedError),
116
}
117

118
impl actix_web::error::ResponseError for ApiError {
119
    fn error_response(&self) -> HttpResponse {
×
120
        HttpResponse::build(self.status_code())
×
121
            .insert_header(ContentType::json())
×
122
            .body(self.to_string())
×
123
    }
×
124

125
    fn status_code(&self) -> StatusCode {
×
126
        match *self {
×
127
            ApiError::TypeError(_) => StatusCode::BAD_REQUEST,
×
128
            ApiError::ApiAuthError(_) => StatusCode::UNAUTHORIZED,
×
129
            ApiError::NotFound(_) => StatusCode::NOT_FOUND,
×
130
            ApiError::ApiGenerationError(_)
131
            | ApiError::SchemaNotFound(_)
132
            | ApiError::InvalidQuery(_) => StatusCode::UNPROCESSABLE_ENTITY,
×
133
            ApiError::InternalError(_)
134
            | ApiError::InitError(_)
135
            | ApiError::SchemaIdentifierNotFound
136
            | ApiError::PortAlreadyInUse(_) => StatusCode::INTERNAL_SERVER_ERROR,
×
137
        }
138
    }
×
139
}
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