forgejo_sdk/
error.rs

1
2#[derive(thiserror::Error, miette::Diagnostic, Debug)]
3pub enum Error {
4    #[error("HTTP error: {_0}")]
5    #[diagnostic(help = "an http error ocurred. check your internet connection, and try again.")]
6    Http(
7        #[from]
8        #[source]
9        reqwest::Error,
10    ),
11
12    #[error("API error: {_0}")]
13    #[diagnostic(transparent)]
14    Api(
15        #[from]
16        #[source]
17        #[diagnostic_source]
18        ApiError,
19    ),
20}
21
22#[derive(thiserror::Error, miette::Diagnostic, Debug)]
23pub enum ApiError {
24    #[error("you weren't authorized to use that endpoint")]
25    #[diagnostic(help = "try to log in with `fjo auth login`")]
26    Unauthorized,
27    #[error("the requested resource was not found")]
28    #[diagnostic(help = "are you sure you didn't make a typo?")]
29    NotFound,
30    #[error(transparent)]
31    #[diagnostic(transparent)]
32    Forbidden(
33        #[from]
34        #[diagnostic_source]
35        ForbiddenError,
36    ),
37}
38
39#[derive(thiserror::Error, miette::Diagnostic, Debug, serde::Deserialize, serde::Serialize)]
40#[error("your account is not allowed to perform that operation")]
41pub struct ForbiddenError {
42    #[source_code]
43    pub message: String,
44    pub url: String,
45}
46
47pub type Result<T, E = Error> = core::result::Result<T, E>;