cat_gateway/service/common/responses/
code_503_service_unavailable.rs

1//! Define `Service Unavailable` Response Body.
2
3use poem_openapi::{types::Example, Object};
4use uuid::Uuid;
5
6use crate::service::common;
7
8#[derive(Object)]
9#[oai(example)]
10/// The service is not available, try again later.
11///
12/// *This is returned when the service either has not started,
13/// or has become unavailable.*
14pub(crate) struct ServiceUnavailable {
15    /// Unique ID of this Server Error so that it can be located easily for debugging.
16    id: common::types::generic::error_uuid::ErrorUuid,
17    /// Error message.
18    // Will not contain sensitive information, internal details or backtraces.
19    msg: common::types::generic::error_msg::ErrorMessage,
20}
21
22impl ServiceUnavailable {
23    /// Create a new Server Error Response Payload.
24    pub(crate) fn new(msg: Option<String>) -> Self {
25        let msg = msg.unwrap_or(
26            "Service Unavailable. Indicates that the server is not ready to handle the request."
27                .to_string(),
28        );
29        let id = Uuid::new_v4();
30
31        Self {
32            id: id.into(),
33            msg: msg.into(),
34        }
35    }
36
37    /// Get the id of this Server Error.
38    pub(crate) fn id(&self) -> Uuid {
39        self.id.clone().into()
40    }
41}
42
43impl Example for ServiceUnavailable {
44    /// Example for the Service Unavailable Payload.
45    fn example() -> Self {
46        Self::new(None)
47    }
48}