Handle ForeignKeyViolation for RBAC errors
This change adds transforming ForeignKeyViolation diesel error kinds
into constraint violation errors.
@@ -417,23 +417,30 @@ impl TryFrom<(models::IdentityModel, Vec<models::AssignmentModel>)> for Assignme
impl From<diesel::result::Error> for RoleBasedAuthorizationStoreError {
fn from(err: diesel::result::Error) -> Self {
match err {
- diesel::result::Error::DatabaseError(
- diesel::result::DatabaseErrorKind::UniqueViolation,
- _,
- ) => RoleBasedAuthorizationStoreError::ConstraintViolation(
+ diesel::result::Error::DatabaseError(ref kind, _) => match kind {
+ diesel::result::DatabaseErrorKind::UniqueViolation => {
+ RoleBasedAuthorizationStoreError::ConstraintViolation(
ConstraintViolationError::from_source_with_violation_type(
ConstraintViolationType::Unique,
Box::new(err),
),
- ),
- diesel::result::Error::DatabaseError(_, _) => {
- RoleBasedAuthorizationStoreError::InternalError(InternalError::from_source(
+ )
+ }
+ diesel::result::DatabaseErrorKind::ForeignKeyViolation => {
+ RoleBasedAuthorizationStoreError::ConstraintViolation(
+ ConstraintViolationError::from_source_with_violation_type(
+ ConstraintViolationType::ForeignKey,
Box::new(err),
- ))
+ ),
+ )
}
_ => RoleBasedAuthorizationStoreError::InternalError(InternalError::from_source(
Box::new(err),
)),
+ },
+ _ => RoleBasedAuthorizationStoreError::InternalError(InternalError::from_source(
+ Box::new(err),
+ )),
}
}
}
