Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
locations-rs: rewrite to actix web framework
Tide was out to be promising, but immature and brought the async-std framework, which has arguable less mature ecosystem. The worst problem was the web client surf, which seemed to be inefficient.
- Loading branch information
Showing
8 changed files
with
646 additions
and
786 deletions.
There are no files selected for viewing
1,255
Cargo.lock
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//! Module that implements our JSON error handling for actix-web. | ||
|
||
use actix_web::{ | ||
body::ResponseBody, | ||
dev::{Body, ServiceResponse}, | ||
middleware::errhandlers::ErrorHandlerResponse, | ||
HttpResponse, | ||
}; | ||
use serde::Serialize; | ||
|
||
/// Process errors from all handlers including the default handler, convert them to JSON. | ||
pub(crate) fn json_error( | ||
mut sres: ServiceResponse<Body>, | ||
) -> Result<ErrorHandlerResponse<Body>, actix_web::Error> { | ||
let response = sres.response_mut(); | ||
let body = match response.take_body() { | ||
ResponseBody::Body(body) | ResponseBody::Other(body) => body, | ||
}; | ||
|
||
// Use existing body as message, otherwise just pretty-printed HTTP code. | ||
let message = match body { | ||
Body::None | Body::Empty => response.status().to_string(), | ||
Body::Bytes(bytes) => String::from_utf8(bytes.to_vec()).expect("valid UTF-8 we've encoded"), | ||
Body::Message(_) => panic!("did not expect Body::Message()"), | ||
}; | ||
|
||
#[derive(Serialize)] | ||
struct ErrorPayload { | ||
message: String, | ||
} | ||
|
||
let body = serde_json::to_string(&ErrorPayload { message })?; | ||
*response = HttpResponse::build(response.status()).content_type("application/json").body(body); | ||
Ok(ErrorHandlerResponse::Response(sres)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters