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

iggy-rs / iggy / 12770513340

14 Jan 2025 03:07PM UTC coverage: 75.399% (+0.05%) from 75.351%
12770513340

push

github

web-flow
Allow replaying messages for high-level consumer, add delete consumer offset (#1436)

291 of 398 new or added lines in 23 files covered. (73.12%)

1 existing line in 1 file now uncovered.

24626 of 32661 relevant lines covered (75.4%)

25528.09 hits per line

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

53.33
/server/src/http/error.rs
1
use axum::http::StatusCode;
2
use axum::response::{IntoResponse, Response};
3
use axum::Json;
4
use iggy::error::IggyError;
5
use serde::Serialize;
6
use thiserror::Error;
7
use tracing::error;
8

9
#[derive(Debug, Error)]
10
pub enum CustomError {
11
    #[error(transparent)]
12
    Error(#[from] IggyError),
13
    #[error("Resource not found")]
14
    ResourceNotFound,
15
}
16

17
#[derive(Debug, Serialize)]
18
pub struct ErrorResponse {
19
    pub id: u32,
20
    pub code: String,
21
    pub reason: String,
22
    pub field: Option<String>,
23
}
24

25
impl IntoResponse for CustomError {
26
    fn into_response(self) -> Response {
12✔
27
        match self {
12✔
28
            CustomError::Error(error) => {
10✔
29
                error!("There was an error: {error}");
10✔
30
                let status_code = match error {
10✔
31
                    IggyError::StreamIdNotFound(_) => StatusCode::NOT_FOUND,
×
32
                    IggyError::TopicIdNotFound(_, _) => StatusCode::NOT_FOUND,
×
33
                    IggyError::PartitionNotFound(_, _, _) => StatusCode::NOT_FOUND,
×
34
                    IggyError::SegmentNotFound => StatusCode::NOT_FOUND,
×
35
                    IggyError::ClientNotFound(_) => StatusCode::NOT_FOUND,
×
36
                    IggyError::ConsumerGroupIdNotFound(_, _) => StatusCode::NOT_FOUND,
×
37
                    IggyError::ConsumerGroupNameNotFound(_, _) => StatusCode::NOT_FOUND,
×
38
                    IggyError::ConsumerGroupMemberNotFound(_, _, _) => StatusCode::NOT_FOUND,
×
NEW
39
                    IggyError::ConsumerOffsetNotFound(_) => StatusCode::NOT_FOUND,
×
40
                    IggyError::ResourceNotFound(_) => StatusCode::NOT_FOUND,
×
41
                    IggyError::Unauthenticated => StatusCode::UNAUTHORIZED,
×
42
                    IggyError::AccessTokenMissing => StatusCode::UNAUTHORIZED,
×
43
                    IggyError::InvalidAccessToken => StatusCode::UNAUTHORIZED,
×
44
                    IggyError::InvalidPersonalAccessToken => StatusCode::UNAUTHORIZED,
×
45
                    IggyError::Unauthorized => StatusCode::FORBIDDEN,
1✔
46
                    _ => StatusCode::BAD_REQUEST,
9✔
47
                };
48
                (status_code, Json(ErrorResponse::from_error(error)))
10✔
49
            }
50
            CustomError::ResourceNotFound => (
2✔
51
                StatusCode::NOT_FOUND,
2✔
52
                Json(ErrorResponse {
2✔
53
                    id: 404,
2✔
54
                    code: "not_found".to_string(),
2✔
55
                    reason: "Resource not found".to_string(),
2✔
56
                    field: None,
2✔
57
                }),
2✔
58
            ),
2✔
59
        }
60
        .into_response()
12✔
61
    }
12✔
62
}
63

64
impl ErrorResponse {
65
    pub fn from_error(error: IggyError) -> Self {
10✔
66
        ErrorResponse {
10✔
67
            id: error.as_code(),
10✔
68
            code: error.as_string().to_string(),
10✔
69
            reason: error.to_string(),
10✔
70
            field: match error {
10✔
71
                IggyError::StreamIdNotFound(_) => Some("stream_id".to_string()),
×
72
                IggyError::TopicIdNotFound(_, _) => Some("topic_id".to_string()),
×
73
                IggyError::PartitionNotFound(_, _, _) => Some("partition_id".to_string()),
×
74
                IggyError::SegmentNotFound => Some("segment_id".to_string()),
×
75
                IggyError::ClientNotFound(_) => Some("client_id".to_string()),
×
76
                IggyError::InvalidStreamName => Some("name".to_string()),
×
77
                IggyError::StreamNameAlreadyExists(_) => Some("name".to_string()),
1✔
78
                IggyError::InvalidTopicName => Some("name".to_string()),
×
79
                IggyError::TopicNameAlreadyExists(_, _) => Some("name".to_string()),
1✔
80
                IggyError::InvalidStreamId => Some("stream_id".to_string()),
×
81
                IggyError::StreamIdAlreadyExists(_) => Some("stream_id".to_string()),
1✔
82
                IggyError::InvalidTopicId => Some("topic_id".to_string()),
×
83
                IggyError::TopicIdAlreadyExists(_, _) => Some("topic_id".to_string()),
1✔
84
                IggyError::InvalidOffset(_) => Some("offset".to_string()),
×
85
                IggyError::InvalidConsumerGroupId => Some("consumer_group_id".to_string()),
×
86
                IggyError::ConsumerGroupIdAlreadyExists(_, _) => {
87
                    Some("consumer_group_id".to_string())
×
88
                }
89
                IggyError::ConsumerGroupNameAlreadyExists(_, _) => Some("name".to_string()),
×
90
                IggyError::UserAlreadyExists => Some("username".to_string()),
1✔
91
                IggyError::PersonalAccessTokenAlreadyExists(_, _) => Some("name".to_string()),
×
92
                _ => None,
5✔
93
            },
94
        }
95
    }
10✔
96
}
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