cat_gateway/service/common/responses/
code_401_unauthorized.rs

1//! Define `Unauthorized` response type.
2
3use poem_openapi::{types::Example, Object};
4use uuid::Uuid;
5
6use crate::service::common;
7
8#[derive(Object)]
9#[oai(example)]
10// Keep this message consistent with the response comment.
11/// The client has not sent valid authentication credentials for the requested
12/// resource.
13pub(crate) struct Unauthorized {
14    /// Unique ID of this Server Error so that it can be located easily for debugging.
15    id: common::types::generic::error_uuid::ErrorUuid,
16    /// Error message.
17    // Will not contain sensitive information, internal details or backtraces.
18    msg: common::types::generic::error_msg::ErrorMessage,
19}
20
21impl Unauthorized {
22    /// Create a new Payload.
23    pub(crate) fn new(msg: Option<String>) -> Self {
24        let msg = msg.unwrap_or(
25            "Your request was not successful because it lacks valid authentication credentials for the requested resource.".to_string(),
26        );
27        let id = Uuid::new_v4();
28
29        Self {
30            id: id.into(),
31            msg: msg.into(),
32        }
33    }
34}
35
36impl Example for Unauthorized {
37    /// Example
38    fn example() -> Self {
39        Self::new(None)
40    }
41}