mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
add custom ExceptError
This commit is contained in:
parent
78d8d21196
commit
72edd75eab
20
src/error.rs
20
src/error.rs
@ -16,7 +16,7 @@ pub use cookie::{ParseError as CookieParseError};
|
|||||||
|
|
||||||
use body::Body;
|
use body::Body;
|
||||||
use httpresponse::HttpResponse;
|
use httpresponse::HttpResponse;
|
||||||
use httpcodes::{HTTPBadRequest, HTTPMethodNotAllowed};
|
use httpcodes::{HTTPBadRequest, HTTPMethodNotAllowed, HTTPExpectationFailed};
|
||||||
|
|
||||||
/// A specialized [`Result`](https://doc.rust-lang.org/std/result/enum.Result.html)
|
/// A specialized [`Result`](https://doc.rust-lang.org/std/result/enum.Result.html)
|
||||||
/// for actix web operations
|
/// for actix web operations
|
||||||
@ -259,6 +259,24 @@ impl ErrorResponse for MultipartError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Error during handling `Expect` header
|
||||||
|
#[derive(Fail, PartialEq, Debug)]
|
||||||
|
pub enum ExpectError {
|
||||||
|
/// Expect header value can not be converted to utf8
|
||||||
|
#[fail(display="Expect header value can not be converted to utf8")]
|
||||||
|
Encoding,
|
||||||
|
/// Unknown expect value
|
||||||
|
#[fail(display="Unknown expect value")]
|
||||||
|
UnknownExpect,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ErrorResponse for ExpectError {
|
||||||
|
|
||||||
|
fn error_response(&self) -> HttpResponse {
|
||||||
|
HTTPExpectationFailed.with_body("Unknown Expect")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Websocket handshake errors
|
/// Websocket handshake errors
|
||||||
#[derive(Fail, PartialEq, Debug)]
|
#[derive(Fail, PartialEq, Debug)]
|
||||||
pub enum WsHandshakeError {
|
pub enum WsHandshakeError {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//! Multipart requests support.
|
//! Multipart requests support
|
||||||
use std::{cmp, fmt};
|
use std::{cmp, fmt};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
@ -8,13 +8,12 @@ use futures::Stream;
|
|||||||
|
|
||||||
use task::{Task, DrainFut};
|
use task::{Task, DrainFut};
|
||||||
use body::Binary;
|
use body::Binary;
|
||||||
use error::Error;
|
use error::{Error, ExpectError};
|
||||||
use context::HttpContext;
|
use context::HttpContext;
|
||||||
use resource::Reply;
|
use resource::Reply;
|
||||||
use payload::Payload;
|
use payload::Payload;
|
||||||
use httprequest::HttpRequest;
|
use httprequest::HttpRequest;
|
||||||
use httpresponse::HttpResponse;
|
use httpresponse::HttpResponse;
|
||||||
use httpcodes::HTTPExpectationFailed;
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -52,7 +51,7 @@ pub trait Route: Actor {
|
|||||||
type State;
|
type State;
|
||||||
|
|
||||||
/// Handle `EXPECT` header. By default respones with `HTTP/1.1 100 Continue`
|
/// Handle `EXPECT` header. By default respones with `HTTP/1.1 100 Continue`
|
||||||
fn expect(req: &HttpRequest, ctx: &mut Self::Context) -> Result<(), HttpResponse>
|
fn expect(req: &HttpRequest, ctx: &mut Self::Context) -> Result<(), Error>
|
||||||
where Self: Actor<Context=HttpContext<Self>>
|
where Self: Actor<Context=HttpContext<Self>>
|
||||||
{
|
{
|
||||||
// handle expect header only for HTTP/1.1
|
// handle expect header only for HTTP/1.1
|
||||||
@ -63,10 +62,10 @@ pub trait Route: Actor {
|
|||||||
ctx.write("HTTP/1.1 100 Continue\r\n\r\n");
|
ctx.write("HTTP/1.1 100 Continue\r\n\r\n");
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(HTTPExpectationFailed.with_body("Unknown Expect"))
|
Err(ExpectError::UnknownExpect.into())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(HTTPExpectationFailed.with_body("Unknown Expect"))
|
Err(ExpectError::Encoding.into())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -61,6 +61,7 @@ pub(crate) trait IoContext: Stream<Item=Frame, Error=Error> + 'static {
|
|||||||
fn disconnected(&mut self);
|
fn disconnected(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Future that resolves when all buffered data get sent
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DrainFut {
|
pub struct DrainFut {
|
||||||
|
Loading…
Reference in New Issue
Block a user