openauth_plugins/access/
error.rs1use std::fmt;
2
3#[derive(Clone, Debug, Eq, PartialEq)]
5pub enum AccessError {
6 EmptyRequest,
8 UnknownResource { resource: String },
10 UnknownAction { resource: String, action: String },
12 ResourceDenied { resource: String },
14 UnauthorizedResource { resource: String },
16 NotAuthorized,
18}
19
20impl fmt::Display for AccessError {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 Self::EmptyRequest => f.write_str("access request must include at least one resource"),
24 Self::UnknownResource { resource } => {
25 write!(f, "unknown access resource `{resource}`")
26 }
27 Self::UnknownAction { resource, action } => {
28 write!(
29 f,
30 "unknown action `{action}` for access resource `{resource}`"
31 )
32 }
33 Self::ResourceDenied { resource } => {
34 write!(f, "not allowed to access resource `{resource}`")
35 }
36 Self::UnauthorizedResource { resource } => {
37 write!(f, "unauthorized to access resource `{resource}`")
38 }
39 Self::NotAuthorized => f.write_str("not authorized"),
40 }
41 }
42}
43
44impl std::error::Error for AccessError {}