cat_gateway/service/common/responses/
code_503_service_unavailable.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! Define `Service Unavailable` Response Body.

use poem_openapi::{types::Example, Object};
use uuid::Uuid;

#[derive(Object)]
#[oai(example)]
/// The service is not available, try again later.
///
/// *This is returned when the service either has not started,
/// or has become unavailable.*
pub(crate) struct ServiceUnavailable {
    /// Unique ID of this Server Error so that it can be located easily for debugging.
    id: Uuid,
    /// Error message.
    // Will not contain sensitive information, internal details or backtraces.
    #[oai(validator(max_length = "100", pattern = "^[0-9a-zA-Z].*$"))]
    msg: String,
}

impl ServiceUnavailable {
    /// Create a new Server Error Response Payload.
    pub(crate) fn new(msg: Option<String>) -> Self {
        let msg = msg.unwrap_or(
            "Service Unavailable. Indicates that the server is not ready to handle the request."
                .to_string(),
        );
        let id = Uuid::new_v4();

        Self { id, msg }
    }

    /// Get the id of this Server Error.
    pub(crate) fn id(&self) -> Uuid {
        self.id
    }
}

impl Example for ServiceUnavailable {
    /// Example for the Service Unavailable Payload.
    fn example() -> Self {
        Self::new(None)
    }
}