Skip to main content

saml2_sp/
error.rs

1// SPDX-FileCopyrightText: 2026 Iya CyberSecurity Solutions, LLC
2// SPDX-License-Identifier: MIT
3
4use std::fmt;
5
6/// A non-success status an identity provider answered with.
7#[derive(Clone, Debug, PartialEq, Eq)]
8pub struct SamlStatus {
9    pub code: String,
10    pub sub_code: String,
11    pub message: String,
12}
13
14/// Every failure this crate reports. Display is the message alone.
15#[derive(Clone, Debug)]
16pub struct SamlError {
17    pub code: String,
18    pub message: String,
19    pub status: Option<SamlStatus>,
20}
21
22impl fmt::Display for SamlError {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        f.write_str(&self.message)
25    }
26}
27
28impl std::error::Error for SamlError {}
29
30pub(crate) fn err(code: &str, message: impl Into<String>) -> SamlError {
31    SamlError { code: code.to_string(), message: message.into(), status: None }
32}
33
34pub(crate) fn err_status(message: impl Into<String>, status: SamlStatus) -> SamlError {
35    SamlError { code: "status".to_string(), message: message.into(), status: Some(status) }
36}