pub struct APIError(/* private fields */);Expand description
The main error type for all QuickBooks API operations.
APIError is a wrapper around APIErrorInner that provides a consistent
error interface for all operations in the library. It implements standard
error traits and can be converted from various underlying error types.
§Examples
use quick_oxibooks::error::APIError;
use quick_oxibooks::{QBContext, Environment};
use ureq::Agent;
fn create_context() -> Result<QBContext, APIError> {
let client = Agent::new_with_defaults();
QBContext::new_from_env(Environment::SANDBOX, &client)
}
let _ = match create_context() {
Ok(_context) => { println!("Context created successfully"); Ok(()) }
Err(e) => { eprintln!("Error: {}", e); Err(e) }
};§Error Conversion
Many error types automatically convert to APIError:
- Network errors from
ureq - JSON parsing errors from
serde_json - QuickBooks-specific validation errors
- Environment variable errors
§Error Handling Patterns
use quick_oxibooks::error::{APIError, APIErrorInner};
use quick_oxibooks::functions::create::QBCreate;
use quickbooks_types::{Customer, QBItem};
fn handle_customer_creation(customer: &Customer, qb_context: &quick_oxibooks::QBContext, client: &ureq::Agent) {
match customer.create(qb_context, client) {
Ok(created) => println!("Created: {:?}", created.id()),
Err(e) => {
match &*e {
APIErrorInner::CreateMissingItems => {
eprintln!("Customer missing required fields");
}
APIErrorInner::BadRequest(_qb_error) => {
eprintln!("QuickBooks rejected the request");
}
_ => eprintln!("Other error: {}", e),
}
}
}
}Trait Implementations§
Source§impl Error for APIError
impl Error for APIError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for APIError
impl !RefUnwindSafe for APIError
impl Send for APIError
impl Sync for APIError
impl Unpin for APIError
impl !UnwindSafe for APIError
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