Skip to content

Commit

Permalink
chore: update root deps
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Jan 30, 2024
1 parent 474f423 commit dc3de98
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 44 deletions.
53 changes: 25 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ rust-version = "1.72"
actix = "0.13"
actix-broker = "0.4"
actix-codec = "0.5"
actix-cors = "0.6"
actix-cors = "0.7"
actix-files = "0.6"
actix-http = "3.5"
actix-identity = "0.6"
actix-identity = "0.7"
actix-multipart = "0.6"
actix-multipart-derive = "0.6"
actix-protobuf = "0.10"
actix-session = "0.8"
actix-session = "0.9"
actix-test = "0.1"
actix-tls = "3.1.1"
actix-tls = "3.2"
actix-utils = "3"
actix-web = "4.4"
actix-web-actors = "4.1"
Expand All @@ -97,7 +97,7 @@ awc = "3.2"
chrono = { version = "0.4.20", default-features = false, features = ["clock", "serde"] }
derive_more = "0.99.7"
dotenvy = "0.15"
env_logger = "0.10"
env_logger = "0.11"
futures-util = { version = "0.3.17", default-features = false, features = ["std"] }
log = "0.4"
openssl = { version = "0.10.60", features = ["v110"] }
Expand Down
2 changes: 1 addition & 1 deletion json/json-decode-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ actix-web.workspace = true

env_logger.workspace = true
log.workspace = true
serde = "1"
serde.workspace = true
3 changes: 2 additions & 1 deletion json/json-decode-error/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use actix_web::{error, post, web, App, HttpRequest, HttpResponse, HttpServer, Responder};
use serde::Deserialize;

#[derive(Deserialize)]
#[derive(Debug, Deserialize)]
struct Info {
name: String,
}
Expand Down Expand Up @@ -38,6 +38,7 @@ async fn main() -> std::io::Result<()> {
.error_handler(json_error_handler),
)
})
.workers(2)
.bind(("127.0.0.1", 8080))?
.run()
.await
Expand Down
15 changes: 6 additions & 9 deletions json/json-error/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
//! 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},
io,
};
use std::{fmt, io};

use actix_web::{http::StatusCode, web, App, HttpResponse, HttpServer, ResponseError};
use serde::Serialize;
use serde_json::{json, to_string_pretty};

#[derive(Debug, Serialize)]
struct Error {
msg: String,
status: u16,
}

impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "{}", to_string_pretty(self).unwrap())
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", serde_json::to_string_pretty(self).unwrap())
}
}

impl ResponseError for Error {
// builds the actual response to send back when an error occurs
fn error_response(&self) -> HttpResponse {
let err_json = json!({ "error": self.msg });
let err_json = serde_json::json!({ "error": self.msg });
HttpResponse::build(StatusCode::from_u16(self.status).unwrap()).json(err_json)
}
}
Expand All @@ -43,6 +39,7 @@ async fn main() -> io::Result<()> {
log::info!("starting HTTP server at http://localhost:8080");

HttpServer::new(|| App::new().service(web::resource("/").route(web::get().to(index))))
.workers(2)
.bind(("127.0.0.1", 8080))?
.run()
.await
Expand Down

0 comments on commit dc3de98

Please sign in to comment.