pub struct ErrorSanitizer { /* private fields */ }Expand description
Sanitizes GraphQL errors before they reach the client.
When configured with enabled = true, strips internal details from
DatabaseError and InternalServerError responses. Client-facing error
codes (validation, auth, not-found, etc.) are always passed through
unchanged so the client can act on them.
Implementations§
Source§impl ErrorSanitizer
impl ErrorSanitizer
Sourcepub const fn new(config: ErrorSanitizationConfig) -> Self
pub const fn new(config: ErrorSanitizationConfig) -> Self
Create a new sanitizer with the given configuration.
Sourcepub fn sanitize(&self, error: GraphQLError) -> GraphQLError
pub fn sanitize(&self, error: GraphQLError) -> GraphQLError
Sanitize a single GraphQL error.
Returns the error unchanged when:
- sanitization is disabled, or
- the error code is client-facing (validation, auth, not-found, etc.)
Sourcepub fn sanitize_all(&self, errors: Vec<GraphQLError>) -> Vec<GraphQLError>
pub fn sanitize_all(&self, errors: Vec<GraphQLError>) -> Vec<GraphQLError>
Sanitize a batch of errors (the GraphQL errors response array).
Sourcepub const fn is_enabled(&self) -> bool
pub const fn is_enabled(&self) -> bool
Whether sanitization is enabled.
Sourcepub const fn should_sanitize_internal(&self) -> bool
pub const fn should_sanitize_internal(&self) -> bool
Whether an internal/server-fault error message should be replaced with a generic one before reaching the client.
This is the same gate sanitize applies to
InternalServerError/DatabaseError on the GraphQL path, exposed so the REST
surface can apply identical sanitization at its error-rendering site (H7 — the
REST path previously wrote raw DB error text into 5xx bodies).
Sourcepub fn internal_error_message(&self) -> String
pub fn internal_error_message(&self) -> String
The generic, client-safe message used to replace internal error detail.
Matches the replacement sanitize uses on the GraphQL path
(the configured custom_error_message, or "An internal error occurred").
Auto Trait Implementations§
impl Freeze for ErrorSanitizer
impl RefUnwindSafe for ErrorSanitizer
impl Send for ErrorSanitizer
impl Sync for ErrorSanitizer
impl Unpin for ErrorSanitizer
impl UnsafeUnpin for ErrorSanitizer
impl UnwindSafe for ErrorSanitizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more