use std error instead of actix error, also result type

master
rascul 2 years ago
parent 2960710987
commit 5b3b329463

@ -3,7 +3,6 @@ use std::io::Write;
use std::path::PathBuf;
use actix_multipart::Multipart;
use actix_web::Error;
use chrono::Utc;
use futures_util::StreamExt;
@ -12,6 +11,8 @@ use serde_json::{Map, Value, to_string_pretty};
use crate::{client, Client};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
#[derive(Debug)]
pub struct WotLog {
/// ID of the log
@ -53,7 +54,7 @@ impl WotLog {
}
}
pub async fn from_payload(payload: Multipart) -> Result<Self, Error> {
pub async fn from_payload(payload: Multipart) -> Result<Self> {
let mut payload = payload;
let mut wotlog = WotLog::new();
@ -88,7 +89,7 @@ impl WotLog {
}
/// Read and parse the log
pub fn parse_log(self: &mut Self) -> Result<(), Error> {
pub fn parse_log(self: &mut Self) -> Result<()> {
let mut map: Map<String, Value> = Map::new();
map.insert("id".into(), self.id.clone().into());
map.insert("player".into(), self.player.clone().into());
@ -100,7 +101,9 @@ impl WotLog {
}
Client::TinTin => (),
Client::ZMud => (),
Client::None => (),
Client::None => {
return Err("no client specified".into())
}
};
self.json = map.into();
@ -109,7 +112,7 @@ impl WotLog {
}
/// save the json to disk
pub fn save(self: &mut Self) -> Result<(), Error> {
pub fn save(self: &mut Self) -> Result<()> {
let path = PathBuf::from("replays");
if !path.is_dir() {

Loading…
Cancel
Save