use std::error::Error;
use std::fmt;
use aws::common::xmlutil::*;
use aws::common::common::*;
use aws::s3::header::*;
use aws::s3::writeparse::*;
#[derive(Debug, Default, Clone, RustcDecodable, RustcEncodable)]
pub struct AWSError {
pub code: String,
pub host_id: String,
pub message: String,
pub request_id: String,
pub resource: String,
pub missing_header_name: String,
pub expanded_message: String,
}
impl fmt::Display for AWSError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Error code: {} - {}", self.code, self.description())
}
}
impl Error for AWSError {
fn description(&self) -> &str {
&self.message
}
}
impl AWSError {
pub fn parse_xml<T: Peek + Next>(tag_name: &str, stack: &mut T) -> Result<AWSError, XmlParseError> {
try!(start_element(tag_name, stack));
let mut obj = AWSError::default();
let mut exp_msg: String = String::new();
loop {
let current_name = try!(peek_at_name(stack));
if current_name == "HostId" {
obj.host_id = try!(HostIdParser::parse_xml("HostId", stack));
continue;
}
if current_name == "RequestId" {
obj.request_id = try!(RequestIdParser::parse_xml("RequestId", stack));
continue;
}
if current_name == "Code" {
obj.code = try!(CodeParser::parse_xml("Code", stack));
continue;
}
if current_name == "Message" {
obj.message = try!(S3ClientMessageParser::parse_xml("Message", stack));
continue;
}
if current_name == "Resource" {
obj.resource = try!(ResourceParser::parse_xml("Resource", stack));
continue;
}
if current_name == "MissingHeaderName" {
obj.missing_header_name = try!(MissingHeaderNameParser::parse_xml("MissingHeaderName", stack));
continue;
}
if current_name == tag_name || current_name.len() == 0 {
break;
}
let tmp = &SkipElementParser::parse_xml(¤t_name, stack).unwrap_or("".to_string());
exp_msg.push_str(tmp);
}
if exp_msg.len() > 0 {
obj.expanded_message = exp_msg;
}
try!(end_element_skip(tag_name, stack));
Ok(obj)
}
}