mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 06:39:22 +02:00
simplify http response construction; deprecate httpcodes
This commit is contained in:
@ -10,7 +10,6 @@ use actix_web::http::header::{CONTENT_TYPE, CONTENT_LENGTH};
|
||||
use actix_web::{Responder, HttpMessage, HttpRequest, HttpResponse};
|
||||
use actix_web::dev::HttpResponseBuilder;
|
||||
use actix_web::error::{Error, PayloadError, ResponseError};
|
||||
use actix_web::httpcodes::{HttpBadRequest, HttpPayloadTooLarge};
|
||||
|
||||
|
||||
#[derive(Fail, Debug)]
|
||||
@ -36,8 +35,8 @@ impl ResponseError for ProtoBufPayloadError {
|
||||
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
match *self {
|
||||
ProtoBufPayloadError::Overflow => HttpPayloadTooLarge.into(),
|
||||
_ => HttpBadRequest.into(),
|
||||
ProtoBufPayloadError::Overflow => HttpResponse::PayloadTooLarge().into(),
|
||||
_ => HttpResponse::BadRequest().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,7 @@ extern crate actix_web;
|
||||
extern crate env_logger;
|
||||
|
||||
use std::env;
|
||||
use actix_web::{
|
||||
http, middleware, server,
|
||||
Application};
|
||||
use actix_web::{http, middleware, server, Application};
|
||||
|
||||
mod user;
|
||||
use user::info;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use actix_web::*;
|
||||
use actix_web::{Error, HttpMessage, HttpResponse, HttpRequest};
|
||||
use futures::Future;
|
||||
|
||||
|
||||
@ -14,6 +14,6 @@ pub fn info(req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
||||
req.json()
|
||||
.from_err()
|
||||
.and_then(|res: Info| {
|
||||
Ok(httpcodes::HttpOk.build().json(res)?)
|
||||
Ok(HttpResponse::Ok().json(res))
|
||||
}).responder()
|
||||
}
|
||||
|
Reference in New Issue
Block a user