digitalocean_api/error.rs
1//! Errors with semantic, crate level meaning.
2//!
3//! This crate uses [`thiserror`](https://github.com/dtolnay/thiserror) to accomplish error handling.
4//!
5//! While functions that return `Error` could return errors from other libraries, the errors in
6//! `ErrorKind` have special semantic meaning to this crate.
7
8use reqwest;
9use serde_json;
10
11/// Errors which have crate specific meanings.
12#[derive(Debug, thiserror::Error)]
13pub enum Error {
14 /// The item does not exist or otherwise cannot be found.
15 #[error("Not Found")]
16 NotFound,
17
18 /// The reqest's API key is invalid or not authorized to view this resource.
19 #[error("Unauthorized")]
20 Unauthorized,
21
22 /// An unexpected status code was returned from the API. Please raise a ticket.
23 #[error("Unexpected status code: {0}")]
24 UnexpectedStatus(reqwest::StatusCode),
25
26 /// The item exists (possibly on another account), the limit on this item has been reached,
27 /// or this request is otherwise unprocessable.
28 #[error("Unprocessable entity: {0}")]
29 UnprocessableEntity(serde_json::Value),
30
31 /// There was a miscellaneous error processing the request. Please look at the documentation of
32 /// `reqwest` to learn more about how to handle these errors.
33 #[error("{0}")]
34 ReqwestError(#[from] reqwest::Error),
35}