This commit is contained in:
2022-09-25 05:39:49 +00:00
committed by GitHub
parent d9d477f954
commit a1b6b96439
2 changed files with 10 additions and 19 deletions

View File

@@ -26,8 +26,16 @@ impl AuthUserContext {
}
async fn handle(&self, mut req: Request<Body>) -> JSONResult {
let root_user = self.ctx.db.get_user(0).await?;
let params = req.get_params().await?;
let root_user = self
.ctx
.db
.get_user(0)
.await
.try_err3(-1001, gettext("Failed to operate database:"))?;
let params = req
.get_params()
.await
.try_err3(-1002, gettext("Failed to get parameters:"))?;
if root_user.is_some() {
// # TODO auth
}

View File

@@ -1,7 +1,6 @@
use crate::ext::json::ToJson2;
#[cfg(test)]
use crate::ext::json::{FromJson, ToJson};
use crate::gettext;
use json::JsonValue;
#[derive(Clone, Debug)]
@@ -85,22 +84,6 @@ impl From<(i32, String, String)> for JSONError {
}
}
impl From<crate::db::PixivDownloaderDbError> for JSONError {
fn from(e: crate::db::PixivDownloaderDbError) -> Self {
Self::from((
-1001,
format!("{} {}", gettext("Failed to operate the database:"), e),
format!("{:?}", e),
))
}
}
impl From<crate::error::PixivDownloaderError> for JSONError {
fn from(e: crate::error::PixivDownloaderError) -> Self {
Self::from((-500, format!("{}", e), format!("{:?}", e)))
}
}
pub type JSONResult = Result<JsonValue, JSONError>;
impl ToJson2 for JSONResult {