Skip to main content

mailjet_rs/client/
status_code.rs

1use hyper::http::StatusCode as HyperStatusCode;
2
3/// HTTP Status Codes defined by the Mailjet API.
4///
5/// Statuses documented in the official documentation are enumerated in the `StatusCode` `enum`.
6/// The documentation provided for each `StatusCode` is taken from the documentation as is:
7///
8/// # Reference
9///
10/// https://dev.mailjet.com/email/reference/overview/errors/
11///
12#[derive(Debug)]
13pub enum StatusCode {
14    /// All went well. Congrats!
15    Ok,
16    /// The `POST` request was successfully executed.
17    Created,
18    /// No content found or expected to return. Returned when a `DELETE` request was successful.
19    NoContent,
20    /// The `PUT` request didn't affect any record.
21    NotModified,
22    /// One or more parameters are missing or maybe misspelled (unknown resource or action).
23    BadRequest,
24    /// You have specified an incorrect API Key / API Secret Key pair.
25    /// You may be unauthorized to access the API or your API key may be inactive.
26    /// Visit API keys Management section to check your keys.
27    Unauthorized,
28    /// You are not authorized to access this resource.
29    Forbidden,
30    /// The resource with the specified ID you are trying to reach does not exist.
31    NotFound,
32    /// The method requested on the resource does not exist.
33    MethodNotAllowed,
34    /// Oops! You have reached the maximum number of calls allowed per minute by our API.
35    /// Please review your integration to reduce the number of calls issued by your system.
36    TooManyRequests,
37    /// Ouch! Something went wrong on our side and we apologize! When such error occurs, it
38    /// will contain an error identifier in its description (e.g. "ErrorIdentifier" : "D4DF574C-0C5F-45C7-BA52-7AA8E533C3DE"),
39    /// which is crucial for us to track the problem and identify the root cause. Please contact our support team, providing the
40    /// error identifier and we will do our best to help.
41    InternalServerError,
42    /// An unkown status code is received from the Mailjet API
43    Unknown(u16),
44}
45
46impl From<HyperStatusCode> for StatusCode {
47    fn from(hyper_status_code: HyperStatusCode) -> Self {
48        match hyper_status_code {
49            HyperStatusCode::OK => StatusCode::Ok,
50            HyperStatusCode::CREATED => StatusCode::Created,
51            HyperStatusCode::NO_CONTENT => StatusCode::NoContent,
52            HyperStatusCode::NOT_MODIFIED => StatusCode::NotModified,
53            HyperStatusCode::BAD_REQUEST => StatusCode::BadRequest,
54            HyperStatusCode::UNAUTHORIZED => StatusCode::Unauthorized,
55            HyperStatusCode::FORBIDDEN => StatusCode::Forbidden,
56            HyperStatusCode::NOT_FOUND => StatusCode::NotFound,
57            HyperStatusCode::METHOD_NOT_ALLOWED => StatusCode::MethodNotAllowed,
58            HyperStatusCode::TOO_MANY_REQUESTS => StatusCode::TooManyRequests,
59            HyperStatusCode::INTERNAL_SERVER_ERROR => StatusCode::InternalServerError,
60            _ => StatusCode::Unknown(hyper_status_code.as_u16()),
61        }
62    }
63}