reintroduce anyhow

This commit is contained in:
marin postma
2021-06-15 17:39:07 +02:00
parent 439db1aae0
commit 02277ec2cf
36 changed files with 110 additions and 154 deletions

View File

@ -9,7 +9,7 @@ use futures::future::{ok, Future, Ready};
use futures::ready;
use pin_project::pin_project;
use crate::error::{ResponseError, AuthenticationError};
use crate::error::{AuthenticationError, ResponseError};
use crate::Data;
#[derive(Clone, Copy)]
@ -117,7 +117,8 @@ where
AuthProj::NoHeader(req) => {
match req.take() {
Some(req) => {
let response = ResponseError::from(AuthenticationError::MissingAuthorizationHeader);
let response =
ResponseError::from(AuthenticationError::MissingAuthorizationHeader);
let response = response.error_response();
let response = req.into_response(response);
Poll::Ready(Ok(response))
@ -134,7 +135,8 @@ where
.get("X-Meili-API-Key")
.map(|h| h.to_str().map(String::from).unwrap_or_default())
.unwrap_or_default();
let response = ResponseError::from(AuthenticationError::InvalidToken(bad_token));
let response =
ResponseError::from(AuthenticationError::InvalidToken(bad_token));
let response = response.error_response();
let response = req.into_response(response);
Poll::Ready(Ok(response))

View File

@ -5,7 +5,7 @@ use std::path::Path;
use flate2::{read::GzDecoder, write::GzEncoder, Compression};
use tar::{Archive, Builder};
pub fn to_tar_gz(src: impl AsRef<Path>, dest: impl AsRef<Path>) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
pub fn to_tar_gz(src: impl AsRef<Path>, dest: impl AsRef<Path>) -> anyhow::Result<()> {
let mut f = File::create(dest)?;
let gz_encoder = GzEncoder::new(&mut f, Compression::default());
let mut tar_encoder = Builder::new(gz_encoder);
@ -16,7 +16,7 @@ pub fn to_tar_gz(src: impl AsRef<Path>, dest: impl AsRef<Path>) -> Result<(), Bo
Ok(())
}
pub fn from_tar_gz(src: impl AsRef<Path>, dest: impl AsRef<Path>) -> Result<(), Box<dyn std::error::Error>> {
pub fn from_tar_gz(src: impl AsRef<Path>, dest: impl AsRef<Path>) -> anyhow::Result<()> {
let f = File::open(&src)?;
let gz = GzDecoder::new(f);
let mut ar = Archive::new(gz);