atomic_lti/
errors.rs

1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4//
5// General error
6//
7#[derive(Error, Debug, PartialEq, Clone, Deserialize, Serialize)]
8pub enum AtomicError {
9  #[error("{0}")]
10  Internal(String),
11}
12
13//
14// Secure errors this includes JWK and JWT errors
15//
16#[derive(Error, Debug, PartialEq, Clone, Deserialize, Serialize)]
17pub enum SecureError {
18  #[error("Unable to decode JWT Token: {0}")]
19  CannotDecodeJwtToken(String),
20
21  #[error("Unable to encode JWT Token: {0}")]
22  CannotEncodeJwtToken(String),
23
24  #[error("Only RSA keys are supported for LTI Id Tokens")]
25  InvalidEncoding,
26
27  #[error("There was a problem with the key: {0}")]
28  KeyError(String),
29
30  #[error("Key Id error: {0}")]
31  InvalidKeyIdError(String),
32
33  #[error("Unable to generate a new JWK: {0}")]
34  JWKGenerateFailed(String),
35
36  #[error("Unable to parse JWK json: {0}")]
37  JWKSetParseFailed(String),
38
39  #[error("There was a problem with the private key: {0}")]
40  PrivateKeyError(String),
41
42  #[error("Unable to generate a new private key: {0}")]
43  PrivateKeyGenerateFailed(String),
44
45  #[error("There are currently no keys available")]
46  EmptyKeys,
47
48  #[error("The requested key does not exist")]
49  InvalidKeyId,
50}
51
52impl From<openssl::error::ErrorStack> for SecureError {
53  fn from(error: openssl::error::ErrorStack) -> Self {
54    SecureError::KeyError(error.to_string())
55  }
56}
57
58impl From<jsonwebtoken::errors::Error> for SecureError {
59  fn from(err: jsonwebtoken::errors::Error) -> Self {
60    SecureError::KeyError(err.to_string())
61  }
62}
63
64//
65// Platform errors
66//
67#[derive(Error, Debug, PartialEq, Clone, Deserialize, Serialize)]
68pub enum PlatformError {
69  #[error("Unable to resolve platform information for iss: {0}")]
70  InvalidIss(String),
71  #[error("Unable to retrieve JWKs from remote JWK server: {0}")]
72  JWKSRequestFailed(String),
73  #[error("Operation not supported: {0}")]
74  UnsupportedOperation(String),
75}
76
77impl From<SecureError> for PlatformError {
78  fn from(err: SecureError) -> PlatformError {
79    PlatformError::InvalidIss(err.to_string())
80  }
81}
82
83//
84// OIDC errors
85//
86#[derive(Error, Debug, PartialEq, Clone, Deserialize, Serialize)]
87pub enum OIDCError {
88  #[error("Allowed time has expired. Please launch the application again")]
89  NonceExpired,
90
91  #[error("Duplicate request. Please launch the application again")]
92  NonceDuplicate,
93
94  #[error("Invalid nonce")]
95  NonceInvalid,
96
97  #[error("Invalid state: {0}")]
98  StateInvalid(String),
99
100  #[error("OIDC store error: {0}")]
101  StoreError(String),
102}
103
104//
105// Client credentials errors
106//
107#[derive(Error, Debug, PartialEq, Clone, Deserialize, Serialize)]
108pub enum ClientCredentialsError {
109  #[error("There was a problem requesting client credentials: {0}")]
110  RequestFailed(String),
111
112  #[error("Client credential requests have been rate limited: {0}")]
113  RateLimited(String),
114
115  #[error("Multiple attempts to request an access token failed: {0}")]
116  RequestLimitReached(String),
117}
118
119//
120// Names and roles errors
121//
122#[derive(Error, Debug, PartialEq, Clone, Deserialize, Serialize)]
123pub enum NamesAndRolesError {
124  #[error("There was a problem requesting names and roles. {0}")]
125  RequestFailed(String),
126}
127
128//
129// Dynamic registration errors
130//
131#[derive(Error, Debug, PartialEq, Clone, Deserialize, Serialize)]
132pub enum DynamicRegistrationError {
133  #[error("There was a problem with the registration configuration. {0}")]
134  InvalidConfig(String),
135
136  #[error("There was a problem with the registration request. {0}")]
137  RequestFailed(String),
138}
139
140impl From<AtomicError> for DynamicRegistrationError {
141  fn from(error: AtomicError) -> Self {
142    DynamicRegistrationError::RequestFailed(error.to_string())
143  }
144}
145
146//
147// Dynamic registration errors
148//
149#[derive(Error, Debug, PartialEq, Clone, Deserialize, Serialize)]
150pub enum AssignmentGradeServicesError {
151  #[error("There was a problem with the assignment grade services request. {0}")]
152  RequestFailed(String),
153}
154
155impl From<AtomicError> for AssignmentGradeServicesError {
156  fn from(error: AtomicError) -> Self {
157    AssignmentGradeServicesError::RequestFailed(error.to_string())
158  }
159}
160
161//
162// Registration errors
163//
164#[derive(Error, Debug, PartialEq, Clone, Deserialize, Serialize)]
165pub enum RegistrationError {
166  #[error("Registration not found: {0}")]
167  NotFound(String),
168
169  #[error("Registration already exists: {0}")]
170  AlreadyExists(String),
171
172  #[error("Invalid registration data: {0}")]
173  InvalidData(String),
174
175  #[error("Database error: {0}")]
176  DatabaseError(String),
177
178  #[error("Registration store error: {0}")]
179  StoreError(String),
180}