Skip to main content

gt_tool/
lib.rs

1use serde::{Deserialize, Serialize};
2
3pub mod api;
4pub mod cli;
5pub mod config;
6pub mod structs;
7
8#[derive(Debug, Deserialize, Serialize)]
9pub struct ApiError {
10    message: String,
11    url: String,
12}
13
14pub(crate) async fn decode_client_error(response: reqwest::Response) -> Result<ApiError> {
15    response
16        .json::<ApiError>()
17        .await
18        .map_err(crate::Error::WrappedReqwestErr)
19}
20
21#[derive(Debug)]
22pub enum Error {
23    Placeholder,     // TODO: Enumerate error modes
24    MissingGiteaUrl, // the gitea URL wasn't specified on the CLI, env, or config file.
25    MissingRepoFRQN, // either the owner, repo, or both weren't specified in the loaded PartialConfig
26    MissingRepoOwner,
27    MissingRepoName,
28    WrappedConfigErr(config::Error),
29    WrappedReqwestErr(reqwest::Error),
30    MissingAuthToken,
31    NoSuchFile, // for release attachment 'file exists' pre-check.
32    NoSuchRelease,
33    ApiErrorMessage(ApiError),
34}
35
36impl From<reqwest::Error> for crate::Error {
37    fn from(value: reqwest::Error) -> Self {
38        Self::WrappedReqwestErr(value)
39    }
40}
41
42impl From<crate::config::Error> for crate::Error {
43    fn from(value: crate::config::Error) -> Self {
44        Self::WrappedConfigErr(value)
45    }
46}
47
48type Result<T> = core::result::Result<T, Error>;