pub struct Error {
pub file: &'static str,
pub line: u32,
pub message: String,
}Fields§
§file: &'static str§line: u32§message: StringImplementations§
Source§impl Error
impl Error
Sourcepub fn new(file: &'static str, line: u32, message: String) -> Self
pub fn new(file: &'static str, line: u32, message: String) -> Self
Examples: Registration middleware
App::new().wrap(ErrorHandlers::new().handler(StatusCode::INTERNAL_SERVER_ERROR, internal_server::handler))Define middleware handler
pub fn handler<B>(mut res: dev::ServiceResponse<B>) -> actix_web::Result<ErrorHandlerResponse<B>> {
println!("{}", "add_internal_server_error_header");
Ok(ErrorHandlerResponse::Response(res.map_into_left_body()))
}Return an error
#[get(path = "/index")]
#[allow(unused)]
async fn index(req: HttpRequest) -> Result<impl Responder, Error> {
if true {
let message = String::from("测试");
Err::<HttpResponse, Error>(Error::new(file!(), line!(), message))
} else {
Ok(success_respond_to(&req, Some("测试")))
}
}Trait Implementations§
Source§impl Error for Error
impl Error for Error
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 ResponseError for Error
impl ResponseError for Error
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
fn error_response(&self) -> HttpResponse
Creates full response for error. Read more
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
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