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
|
//! ref: composer/src/Composer/Downloader/TransportException.php
use shirabe_php_shim::PhpMixed;
#[derive(Debug)]
pub struct TransportException {
pub message: String,
pub code: i64,
pub(crate) headers: Option<Vec<String>>,
pub(crate) response: Option<String>,
pub(crate) status_code: Option<i64>,
pub(crate) response_info: Vec<PhpMixed>,
}
impl TransportException {
pub fn new(message: String, code: i64) -> Self {
Self {
message,
code,
headers: None,
response: None,
status_code: None,
response_info: vec![],
}
}
/// PHP exposes ($message, $code = 0) — alias of `new` used at call sites where the
/// status/exception code is provided up-front.
pub fn new_with_code(message: String, code: i64) -> Self {
Self::new(message, code)
}
pub fn get_code(&self) -> i64 {
self.code
}
pub fn get_message(&self) -> &str {
&self.message
}
pub fn set_headers(&mut self, headers: Vec<String>) {
self.headers = Some(headers);
}
pub fn get_headers(&self) -> Option<&Vec<String>> {
self.headers.as_ref()
}
pub fn set_response(&mut self, response: Option<String>) {
self.response = response;
}
pub fn get_response(&self) -> Option<&str> {
self.response.as_deref()
}
pub fn set_status_code(&mut self, status_code: Option<i64>) {
self.status_code = status_code;
}
pub fn get_status_code(&self) -> Option<i64> {
self.status_code
}
pub fn get_response_info(&self) -> &Vec<PhpMixed> {
&self.response_info
}
pub fn set_response_info(&mut self, response_info: Vec<PhpMixed>) {
self.response_info = response_info;
}
}
impl std::fmt::Display for TransportException {
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
impl std::error::Error for TransportException {}
|