Skip to main content

ErrorBuilder

Struct ErrorBuilder 

Source
pub struct ErrorBuilder { /* private fields */ }
Expand description

统一的错误构建器,避免直接依赖枚举内部字段

Implementations§

Source§

impl ErrorBuilder

Source

pub fn new(kind: BuilderKind) -> Self

创建指定类型的错误构建器

Source

pub fn message(self, msg: impl Into<String>) -> Self

设置错误消息

Source

pub fn code(self, code: ErrorCode) -> Self

设置错误码

Source

pub fn status(self, status: u16) -> Self

设置 HTTP 状态码

Source

pub fn endpoint(self, endpoint: impl Into<String>) -> Self

设置 API 端点

Source

pub fn field(self, field: impl Into<String>) -> Self

设置验证字段名

Source

pub fn source<E: Error + Send + Sync + 'static>(self, err: E) -> Self

设置源错误

Source

pub fn policy(self, policy: RetryPolicy) -> Self

设置重试策略

Source

pub fn request_id(self, req: impl Into<String>) -> Self

设置请求 ID

Source

pub fn operation(self, op: impl Into<String>) -> Self

设置操作名称

Source

pub fn component(self, comp: impl Into<String>) -> Self

设置组件名称

Source

pub fn user_message(self, msg: impl Into<String>) -> Self

设置用户友好的错误消息

Source

pub fn context(self, key: impl Into<String>, val: impl Into<String>) -> Self

添加上下文键值对

Source

pub fn duration(self, duration: Duration) -> Self

设置超时时长

Source

pub fn limit(self, limit: u32) -> Self

设置限流次数

Source

pub fn window(self, window: Duration) -> Self

设置限流时间窗口

Source

pub fn reset_after(self, reset: Duration) -> Self

设置限流重置时间

Source

pub fn service(self, service: impl Into<String>) -> Self

设置服务名

Source

pub fn retry_after(self, retry_after: Duration) -> Self

设置重试等待时间

Source

pub fn build(self) -> CoreError

构建 CoreError 实例

Trait Implementations§

Source§

impl Debug for ErrorBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more