1use reqwest::{Method, StatusCode, Url};
4use std::error::Error;
5use thiserror::Error;
6
7pub type MoocClientResult<T> = Result<T, Box<MoocClientError>>;
8
9#[derive(Debug, Error)]
10pub enum MoocClientError {
11 #[error("HTTP error {status} for {url}: {error}. Obsolete client: {obsolete_client}.")]
12 HttpError {
13 url: Url,
14 status: StatusCode,
15 error: String,
16 obsolete_client: bool,
17 },
18 #[error("Connection error trying to {0} {1}")]
19 ConnectionError(Method, Url, #[source] reqwest::Error),
20 #[error("Failed to parse as URL: {0}")]
21 UrlParse(String, #[source] url::ParseError),
22 #[error("Authentication required")]
23 NotAuthenticated,
24 #[error("Failed to attach file to submission form: {error}")]
25 AttachFileToForm { error: Box<dyn Error + Send + Sync> },
26 #[error("Failed to send {method} request to {url}: {error}.")]
27 SendingRequest {
28 method: Method,
29 url: Url,
30 error: Box<dyn Error + Send + Sync>,
31 },
32 #[error("Failed to read {method} response body from {url}: {error}.")]
33 ReadingResponseBody {
34 method: Method,
35 url: Url,
36 error: Box<dyn Error + Send + Sync>,
37 },
38 #[error("Failed to deserialize response body from {url}: {error}.")]
39 DeserializingResponse {
40 url: Url,
41 error: Box<dyn Error + Send + Sync>,
42 },
43 #[error(transparent)]
44 JsonError(#[from] tmc_langs_util::JsonError),
45}