pub struct ApiErrorResponse {
pub code: u32,
pub message: String,
pub request_id: Option<String>,
}Expand description
Detailed API error response from Alpaca.
Fields§
§code: u32The error code returned by Alpaca.
message: StringThe error message.
request_id: Option<String>Optional request ID for debugging.
Implementations§
Source§impl ApiErrorResponse
impl ApiErrorResponse
Sourcepub fn new(code: u32, message: impl Into<String>) -> Self
pub fn new(code: u32, message: impl Into<String>) -> Self
Creates a new API error response.
Examples found in repository?
examples/base_error_handling.rs (line 174)
134fn demonstrate_error_matching() {
135 let error = AlpacaError::api_with_details(
136 404,
137 "order not found",
138 ApiErrorCode::NotFound,
139 Some("req-12345".to_string()),
140 );
141
142 // Pattern match on error type
143 match &error {
144 AlpacaError::Api {
145 status,
146 message,
147 error_code,
148 request_id,
149 } => {
150 println!(" API Error detected:");
151 println!(" - Status: {}", status);
152 println!(" - Message: {}", message);
153 println!(" - Error code: {:?}", error_code);
154 println!(" - Request ID: {:?}", request_id);
155 }
156 AlpacaError::RateLimit {
157 retry_after_secs, ..
158 } => {
159 println!(" Rate limited, retry after {} seconds", retry_after_secs);
160 }
161 _ => {
162 println!(" Other error: {}", error);
163 }
164 }
165
166 // Use helper methods
167 println!("\n Helper methods:");
168 println!(" - status_code(): {:?}", error.status_code());
169 println!(" - request_id(): {:?}", error.request_id());
170 println!(" - is_retryable(): {}", error.is_retryable());
171
172 // API error response parsing
173 let response =
174 ApiErrorResponse::new(40410000, "resource not found").with_request_id("req-67890");
175 println!("\n Parsed API response:");
176 println!(" - Code: {}", response.code);
177 println!(" - Message: {}", response.message);
178 println!(" - Typed code: {:?}", response.error_code());
179}Sourcepub fn with_request_id(self, request_id: impl Into<String>) -> Self
pub fn with_request_id(self, request_id: impl Into<String>) -> Self
Sets the request ID.
Examples found in repository?
examples/base_error_handling.rs (line 174)
134fn demonstrate_error_matching() {
135 let error = AlpacaError::api_with_details(
136 404,
137 "order not found",
138 ApiErrorCode::NotFound,
139 Some("req-12345".to_string()),
140 );
141
142 // Pattern match on error type
143 match &error {
144 AlpacaError::Api {
145 status,
146 message,
147 error_code,
148 request_id,
149 } => {
150 println!(" API Error detected:");
151 println!(" - Status: {}", status);
152 println!(" - Message: {}", message);
153 println!(" - Error code: {:?}", error_code);
154 println!(" - Request ID: {:?}", request_id);
155 }
156 AlpacaError::RateLimit {
157 retry_after_secs, ..
158 } => {
159 println!(" Rate limited, retry after {} seconds", retry_after_secs);
160 }
161 _ => {
162 println!(" Other error: {}", error);
163 }
164 }
165
166 // Use helper methods
167 println!("\n Helper methods:");
168 println!(" - status_code(): {:?}", error.status_code());
169 println!(" - request_id(): {:?}", error.request_id());
170 println!(" - is_retryable(): {}", error.is_retryable());
171
172 // API error response parsing
173 let response =
174 ApiErrorResponse::new(40410000, "resource not found").with_request_id("req-67890");
175 println!("\n Parsed API response:");
176 println!(" - Code: {}", response.code);
177 println!(" - Message: {}", response.message);
178 println!(" - Typed code: {:?}", response.error_code());
179}Sourcepub fn error_code(&self) -> ApiErrorCode
pub fn error_code(&self) -> ApiErrorCode
Returns the typed error code.
Examples found in repository?
examples/base_error_handling.rs (line 178)
134fn demonstrate_error_matching() {
135 let error = AlpacaError::api_with_details(
136 404,
137 "order not found",
138 ApiErrorCode::NotFound,
139 Some("req-12345".to_string()),
140 );
141
142 // Pattern match on error type
143 match &error {
144 AlpacaError::Api {
145 status,
146 message,
147 error_code,
148 request_id,
149 } => {
150 println!(" API Error detected:");
151 println!(" - Status: {}", status);
152 println!(" - Message: {}", message);
153 println!(" - Error code: {:?}", error_code);
154 println!(" - Request ID: {:?}", request_id);
155 }
156 AlpacaError::RateLimit {
157 retry_after_secs, ..
158 } => {
159 println!(" Rate limited, retry after {} seconds", retry_after_secs);
160 }
161 _ => {
162 println!(" Other error: {}", error);
163 }
164 }
165
166 // Use helper methods
167 println!("\n Helper methods:");
168 println!(" - status_code(): {:?}", error.status_code());
169 println!(" - request_id(): {:?}", error.request_id());
170 println!(" - is_retryable(): {}", error.is_retryable());
171
172 // API error response parsing
173 let response =
174 ApiErrorResponse::new(40410000, "resource not found").with_request_id("req-67890");
175 println!("\n Parsed API response:");
176 println!(" - Code: {}", response.code);
177 println!(" - Message: {}", response.message);
178 println!(" - Typed code: {:?}", response.error_code());
179}Trait Implementations§
Source§impl Clone for ApiErrorResponse
impl Clone for ApiErrorResponse
Source§fn clone(&self) -> ApiErrorResponse
fn clone(&self) -> ApiErrorResponse
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ApiErrorResponse
impl Debug for ApiErrorResponse
Source§impl<'de> Deserialize<'de> for ApiErrorResponse
impl<'de> Deserialize<'de> for ApiErrorResponse
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ApiErrorResponse
impl RefUnwindSafe for ApiErrorResponse
impl Send for ApiErrorResponse
impl Sync for ApiErrorResponse
impl Unpin for ApiErrorResponse
impl UnwindSafe for ApiErrorResponse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more