Skip to content

Commit

Permalink
refactor: rename errors to error
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Aug 20, 2024
1 parent f39ea43 commit 4677663
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::Serialize;

use crate::{
consts::{EXECUTE_URL, RUNTIMES_URL},
errors::Errors,
error::Error,
lang::{ApiResponse, Language, Response},
};

Expand Down Expand Up @@ -53,10 +53,10 @@ impl Client {
.and_then(|l| Some(l.version.clone())))
}

pub async fn execute(self) -> Result<Response, Errors> {
pub async fn execute(self) -> Result<Response, Error> {
let version = match self.get_lang_version().await {
Err(err) => return Err(Errors::Unknown(err.to_string())),
Ok(None) => return Err(Errors::InvalidLanguage),
Err(err) => return Err(Error::Unknown(err.to_string())),
Ok(None) => return Err(Error::InvalidLanguage),
Ok(Some(v)) => v,
};
let mut files = vec![FileData {
Expand Down Expand Up @@ -84,14 +84,14 @@ impl Client {
.send()
.await;
let data = match data {
Err(e) => return Err(Errors::Unknown(e.to_string())),
Err(e) => return Err(Error::Unknown(e.to_string())),
Ok(res) => res,
};

match data.json::<ApiResponse>().await {
Ok(ApiResponse::Good(response)) => Ok(response),
Ok(ApiResponse::Error(error)) => Err(Errors::Unknown(error.message().to_owned())),
Err(err) => Err(Errors::Unknown(err.to_string())),
Ok(ApiResponse::Error(error)) => Err(Error::Unknown(error.message().to_owned())),
Err(err) => Err(Error::Unknown(err.to_string())),
}
}
}
Expand Down Expand Up @@ -132,9 +132,9 @@ impl ClientBuilder {
}
}

pub fn build(self) -> Result<Client, Errors> {
let language = self.language.ok_or(Errors::MissingLang)?;
let main_file = self.main_file.ok_or(Errors::MissingMain)?;
pub fn build(self) -> Result<Client, Error> {
let language = self.language.ok_or(Error::MissingLang)?;
let main_file = self.main_file.ok_or(Error::MissingMain)?;

let http_client = reqwest::ClientBuilder::new()
.user_agent("fewwis-bot/@romancitodev")
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs → src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Errors {
pub enum Error {
#[error("Unknown language. See the API instead.")]
UnknownLang,
#[error("Missing language.")]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod client;
pub mod consts;
pub mod errors;
pub mod error;
pub mod lang;

0 comments on commit 4677663

Please sign in to comment.