use security_core::types::{ActorId, RequestId, TenantId};
#[derive(Debug, Default)]
pub struct ErrorReportBuilder {
cause: String,
component: Option<&'static str>,
request_id: Option<RequestId>,
actor_id: Option<ActorId>,
tenant_id: Option<TenantId>,
backtrace: Option<String>,
}
impl ErrorReportBuilder {
#[must_use]
pub fn cause(mut self, cause: impl Into<String>) -> Self {
self.cause = cause.into();
self
}
#[must_use]
pub fn component(mut self, component: &'static str) -> Self {
self.component = Some(component);
self
}
#[must_use]
pub fn request_id(mut self, id: RequestId) -> Self {
self.request_id = Some(id);
self
}
#[must_use]
pub fn actor_id(mut self, id: ActorId) -> Self {
self.actor_id = Some(id);
self
}
#[must_use]
pub fn tenant_id(mut self, id: TenantId) -> Self {
self.tenant_id = Some(id);
self
}
#[must_use]
pub fn with_backtrace(mut self, backtrace: impl Into<String>) -> Self {
self.backtrace = Some(backtrace.into());
self
}
#[must_use]
pub fn build(self) -> ErrorReport {
ErrorReport {
cause: self.cause,
component: self.component.unwrap_or("unknown"),
request_id: self.request_id,
actor_id: self.actor_id,
tenant_id: self.tenant_id,
backtrace: self.backtrace,
}
}
}
#[derive(Debug)]
pub struct ErrorReport {
pub(crate) cause: String,
pub(crate) component: &'static str,
pub(crate) request_id: Option<RequestId>,
pub(crate) actor_id: Option<ActorId>,
pub(crate) tenant_id: Option<TenantId>,
pub(crate) backtrace: Option<String>,
}
impl ErrorReport {
#[must_use]
pub fn builder() -> ErrorReportBuilder {
ErrorReportBuilder::default()
}
#[must_use]
pub fn cause(&self) -> &str {
&self.cause
}
#[must_use]
pub fn component(&self) -> &str {
self.component
}
#[must_use]
pub fn request_id(&self) -> Option<&RequestId> {
self.request_id.as_ref()
}
#[must_use]
pub fn actor_id(&self) -> Option<&ActorId> {
self.actor_id.as_ref()
}
#[must_use]
pub fn tenant_id(&self) -> Option<&TenantId> {
self.tenant_id.as_ref()
}
#[must_use]
pub fn backtrace(&self) -> Option<&str> {
self.backtrace.as_deref()
}
}