1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use anyhow;
use Result;
use Client;
use DeserializeOwned;
use Deserialize;
use Serialize;
/// Represents an error response from the GitHub API.
///
/// This struct contains information about an error response from the GitHub
/// API, including the error message and the URL of the documentation related to
/// the error.
///
/// # Fields
///
/// * `message: String` - The error message from the GitHub API.
/// * `documentation_url: String` - The URL of the documentation related to the
/// error.
///
/// # Example
///
/// ```rust
/// let error_response = ErrorResponse {
/// message: "Not Found".to_string(),
/// documentation_url: "https://docs.github.com/rest".to_string(),
/// };
/// println!("The error message is {}", error_response.message);
/// println!(
/// "The documentation URL is {}",
/// error_response.documentation_url
/// );
/// ```
pub async
/// Deserializes a JSON response from the GitHub API.
///
/// # Parameters
///
/// * `response: String` - The JSON response from the GitHub API as a string.
///
/// # Returns
///
/// * `Result<T>` - The deserialized response as the specified type `T`, or an
/// error if the response could not be deserialized or contains an error
/// message.
///
/// # Errors
///
/// This function will return an error if the response contains a "message"
/// field (indicating an error from the GitHub API), or if the response could
/// not be deserialized into the specified type `T`.
///
/// # Example
///
/// ```rust
/// let response = "{\"data\": \"some data\"}";
/// let result: Result<MyType> = deserialize_response(response);
/// match result {
/// Ok(data) => println!("Received data: {:?}", data),
/// Err(e) => println!("An error occurred: {:?}", e),
/// }
/// ```