potree_auth/render/application/
error.rs1use crate::authorization::domain::action::Action;
2use crate::authorization::domain::error::AuthorizationEngineError;
3use crate::authorization::domain::resource::ResourceIdentifier;
4use crate::authorization::domain::resource::ResourceType;
5use crate::project::domain::ProjectId;
6use crate::project::ports::project_repository::ProjectRepositoryError;
7use crate::user::domain::User;
8
9#[derive(Debug, thiserror::Error)]
10pub enum RenderingServiceError {
11 #[error("project ({id}) not found")]
12 ProjectNotFound { id: ProjectId },
13
14 #[error("{} is not authorized to {} the {:?}: {:?}", user.name, action, resource_type, resource_identifier)]
15 NotAuthorized {
16 user: Box<User>,
17 action: Action,
18 resource_identifier: Option<ResourceIdentifier>,
19 resource_type: ResourceType,
20 },
21
22 #[error("user is not authenticated")]
23 NotAuthenticated,
24
25 #[error("the server is not configured correctly: {message}")]
26 ServerConfiguration { message: String },
27
28 #[error("{message}")]
29 Infrastucture { message: String },
30}
31
32impl From<ProjectRepositoryError> for RenderingServiceError {
33 fn from(value: ProjectRepositoryError) -> Self {
34 match value {
35 ProjectRepositoryError::ResourceNotFound { id }
36 | ProjectRepositoryError::Parsing { id } => Self::ProjectNotFound { id },
37 ProjectRepositoryError::Infrastucture { message } => Self::Infrastucture { message },
38 }
39 }
40}
41
42impl From<AuthorizationEngineError> for RenderingServiceError {
43 fn from(value: AuthorizationEngineError) -> Self {
44 match value {
45 AuthorizationEngineError::NotAuthorized {
46 user,
47 action,
48 resource_identifier,
49 resource_type,
50 } => Self::NotAuthorized {
51 user,
52 action,
53 resource_identifier,
54 resource_type,
55 },
56 AuthorizationEngineError::NotAuthenticated => Self::NotAuthenticated,
57 }
58 }
59}
60
61impl From<web_route::error::WebRouteError> for RenderingServiceError {
62 fn from(value: web_route::error::WebRouteError) -> Self {
63 Self::ServerConfiguration {
64 message: format!("unable to build `WebRoute`: {value}"),
65 }
66 }
67}
68
69impl From<super::super::domain::error::RenderDomainError> for RenderingServiceError {
70 fn from(value: super::super::domain::error::RenderDomainError) -> Self {
71 match value {
72 crate::render::domain::error::RenderDomainError::InvalidRoutePopulation { .. } => {
73 Self::ServerConfiguration {
74 message: value.to_string(),
75 }
76 }
77 }
78 }
79}