use http::{Response, StatusCode};
use super::ProtectionError;
pub trait ResponseForProtectionError<B>: Clone {
fn response_for_protection_error(&mut self, error: ProtectionError) -> Response<B>;
}
impl<F, B> ResponseForProtectionError<B> for F
where
F: FnMut(ProtectionError) -> Response<B> + Clone,
{
fn response_for_protection_error(&mut self, error: ProtectionError) -> Response<B> {
self(error)
}
}
#[derive(Clone, Copy, Debug, Default)]
#[non_exhaustive]
pub struct DefaultResponseForProtectionError;
impl<B: Default> ResponseForProtectionError<B> for DefaultResponseForProtectionError {
fn response_for_protection_error(&mut self, _error: ProtectionError) -> Response<B> {
let mut response = Response::new(B::default());
*response.status_mut() = StatusCode::FORBIDDEN;
response
}
}