pub struct SimpleKeyExtractionError<T: Display + Debug> {
pub body: T,
pub status_code: StatusCode,
pub content_type: ContentType,
}Expand description
A simple struct to create error, by default the status is 500 server error and content-type is plintext
Fields§
§body: TThe response body of the error.
status_code: StatusCodeThe status code of the error.
content_type: ContentTypeThe content type of the error.
Implementations§
Source§impl<T: Display + Debug> SimpleKeyExtractionError<T>
impl<T: Display + Debug> SimpleKeyExtractionError<T>
Sourcepub fn new(body: T) -> Self
pub fn new(body: T) -> Self
Create new instance by body
§Example
use actix_governor::SimpleKeyExtractionError;
use actix_http::StatusCode;
use actix_web::http::header::ContentType;
let my_error = SimpleKeyExtractionError::new("Some error content");
assert_eq!(my_error.body, "Some error content");
assert_eq!(my_error.content_type, ContentType::plaintext());
assert_eq!(my_error.status_code, StatusCode::INTERNAL_SERVER_ERROR);Sourcepub fn set_status_code(self, status_code: StatusCode) -> Self
pub fn set_status_code(self, status_code: StatusCode) -> Self
Set a new status code, the default is StatusCode::INTERNAL_SERVER_ERROR
§Example
use actix_governor::SimpleKeyExtractionError;
use actix_http::StatusCode;
use actix_web::http::header::ContentType;
let my_error = SimpleKeyExtractionError::new("Some error content")
.set_status_code(StatusCode::FORBIDDEN);
assert_eq!(my_error.body, "Some error content");
assert_eq!(my_error.content_type, ContentType::plaintext());
assert_eq!(my_error.status_code, StatusCode::FORBIDDEN);Sourcepub fn set_content_type(self, content_type: ContentType) -> Self
pub fn set_content_type(self, content_type: ContentType) -> Self
Set a new content type, the default is text/plain
§Example
use actix_governor::SimpleKeyExtractionError;
use actix_http::StatusCode;
use actix_web::http::header::ContentType;
let my_error = SimpleKeyExtractionError::new(r#"{"msg":"Some error content"}"#)
.set_content_type(ContentType::json());
assert_eq!(my_error.body, r#"{"msg":"Some error content"}"#);
assert_eq!(my_error.content_type, ContentType::json());
assert_eq!(my_error.status_code, StatusCode::INTERNAL_SERVER_ERROR);Trait Implementations§
Source§impl<T: Display + Debug> Error for SimpleKeyExtractionError<T>
impl<T: Display + Debug> Error for SimpleKeyExtractionError<T>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl<T: Display + Debug> ResponseError for SimpleKeyExtractionError<T>
impl<T: Display + Debug> ResponseError for SimpleKeyExtractionError<T>
Source§fn status_code(&self) -> StatusCode
fn status_code(&self) -> StatusCode
Returns appropriate status code for error. Read more
Source§fn error_response(&self) -> HttpResponse<BoxBody>
fn error_response(&self) -> HttpResponse<BoxBody>
Creates full response for error. Read more
Auto Trait Implementations§
impl<T> Freeze for SimpleKeyExtractionError<T>where
T: Freeze,
impl<T> RefUnwindSafe for SimpleKeyExtractionError<T>where
T: RefUnwindSafe,
impl<T> Send for SimpleKeyExtractionError<T>where
T: Send,
impl<T> Sync for SimpleKeyExtractionError<T>where
T: Sync,
impl<T> Unpin for SimpleKeyExtractionError<T>where
T: Unpin,
impl<T> UnwindSafe for SimpleKeyExtractionError<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more