mirror of
https://github.com/actix/examples
synced 2025-06-26 17:17:42 +02:00
update actix web to stable version
This commit is contained in:
@ -4,7 +4,7 @@ version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4.0.0-rc.3"
|
||||
actix-web = "4"
|
||||
failure = "0.1"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
@ -1,9 +1,11 @@
|
||||
// This example is meant to show how to automatically generate a json error response when something goes wrong.
|
||||
use std::fmt::{Display, Formatter, Result as FmtResult};
|
||||
use std::io;
|
||||
//! This example is meant to show how to automatically generate a json error response when something goes wrong.
|
||||
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::{web, App, HttpServer, ResponseError};
|
||||
use std::{
|
||||
fmt::{Display, Formatter, Result as FmtResult},
|
||||
io,
|
||||
};
|
||||
|
||||
use actix_web::{http::StatusCode, web, App, HttpResponse, HttpServer, ResponseError};
|
||||
use serde::Serialize;
|
||||
use serde_json::{json, to_string_pretty};
|
||||
|
||||
@ -21,13 +23,13 @@ impl Display for Error {
|
||||
|
||||
impl ResponseError for Error {
|
||||
// builds the actual response to send back when an error occurs
|
||||
fn error_response(&self) -> web::HttpResponse {
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
let err_json = json!({ "error": self.msg });
|
||||
web::HttpResponse::build(StatusCode::from_u16(self.status).unwrap()).json(err_json)
|
||||
HttpResponse::build(StatusCode::from_u16(self.status).unwrap()).json(err_json)
|
||||
}
|
||||
}
|
||||
|
||||
async fn index() -> Result<web::HttpResponse, Error> {
|
||||
async fn index() -> Result<HttpResponse, Error> {
|
||||
Err(Error {
|
||||
msg: "an example error message".to_string(),
|
||||
status: 400,
|
||||
|
Reference in New Issue
Block a user