Remove LoadError.

This commit is contained in:
Ms2ger 2016-12-08 10:25:23 -10:00
parent c9370e04a5
commit 87979ef65e

View file

@ -40,7 +40,6 @@ use resource_thread::AuthCache;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::collections::HashSet; use std::collections::HashSet;
use std::error::Error; use std::error::Error;
use std::fmt;
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
use std::iter::FromIterator; use std::iter::FromIterator;
use std::mem::swap; use std::mem::swap;
@ -129,7 +128,7 @@ struct NetworkHttpRequestFactory {
impl NetworkHttpRequestFactory { impl NetworkHttpRequestFactory {
fn create(&self, url: ServoUrl, method: Method, headers: Headers) fn create(&self, url: ServoUrl, method: Method, headers: Headers)
-> Result<HyperRequest<Fresh>, LoadError> { -> Result<HyperRequest<Fresh>, NetworkError> {
let connection = HyperRequest::with_connector(method, let connection = HyperRequest::with_connector(method,
url.clone().into_url().unwrap(), url.clone().into_url().unwrap(),
&*self.connector); &*self.connector);
@ -152,15 +151,14 @@ impl NetworkHttpRequestFactory {
} }
let error_report = error_report.join("<br>\n"); let error_report = error_report.join("<br>\n");
return Err(LoadError::new(url, LoadErrorType::Ssl { reason: error_report })); return Err(NetworkError::SslValidation(url, error_report));
} }
} }
} }
let mut request = match connection { let mut request = match connection {
Ok(req) => req, Ok(req) => req,
Err(e) => return Err( Err(e) => return Err(NetworkError::Internal(e.description().to_owned())),
LoadError::new(url, LoadErrorType::Connection { reason: e.description().to_owned() })),
}; };
*request.headers_mut() = headers; *request.headers_mut() = headers;
@ -168,42 +166,6 @@ impl NetworkHttpRequestFactory {
} }
} }
#[derive(Debug)]
struct LoadError {
pub url: ServoUrl,
pub error: LoadErrorType,
}
impl LoadError {
pub fn new(url: ServoUrl, error: LoadErrorType) -> LoadError {
LoadError {
url: url,
error: error,
}
}
}
#[derive(Eq, PartialEq, Debug)]
enum LoadErrorType {
Connection { reason: String },
Ssl { reason: String },
}
impl fmt::Display for LoadErrorType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for LoadErrorType {
fn description(&self) -> &str {
match *self {
LoadErrorType::Connection { ref reason } => reason,
LoadErrorType::Ssl { ref reason } => reason,
}
}
}
fn set_default_accept_encoding(headers: &mut Headers) { fn set_default_accept_encoding(headers: &mut Headers) {
if headers.has::<AcceptEncoding>() { if headers.has::<AcceptEncoding>() {
return return
@ -444,7 +406,7 @@ fn obtain_response(request_factory: &NetworkHttpRequestFactory,
iters: u32, iters: u32,
request_id: Option<&str>, request_id: Option<&str>,
is_xhr: bool) is_xhr: bool)
-> Result<(WrappedHttpResponse, Option<ChromeToDevtoolsControlMsg>), LoadError> { -> Result<(WrappedHttpResponse, Option<ChromeToDevtoolsControlMsg>), NetworkError> {
let null_data = None; let null_data = None;
let connection_url = replace_hosts(&url); let connection_url = replace_hosts(&url);
@ -495,14 +457,12 @@ fn obtain_response(request_factory: &NetworkHttpRequestFactory,
let mut request_writer = match request.start() { let mut request_writer = match request.start() {
Ok(streaming) => streaming, Ok(streaming) => streaming,
Err(e) => return Err(LoadError::new(connection_url, Err(e) => return Err(NetworkError::Internal(e.description().to_owned())),
LoadErrorType::Connection { reason: e.description().to_owned() })),
}; };
if let Some(ref data) = *request_body { if let Some(ref data) = *request_body {
if let Err(e) = request_writer.write_all(&data) { if let Err(e) = request_writer.write_all(&data) {
return Err(LoadError::new(connection_url, return Err(NetworkError::Internal(e.description().to_owned()))
LoadErrorType::Connection { reason: e.description().to_owned() }))
} }
} }
@ -512,8 +472,7 @@ fn obtain_response(request_factory: &NetworkHttpRequestFactory,
debug!("connection aborted ({:?}), possibly stale, trying new connection", io_error.description()); debug!("connection aborted ({:?}), possibly stale, trying new connection", io_error.description());
continue; continue;
}, },
Err(e) => return Err(LoadError::new(connection_url, Err(e) => return Err(NetworkError::Internal(e.description().to_owned())),
LoadErrorType::Connection { reason: e.description().to_owned() })),
}; };
let send_end = precise_time_ms(); let send_end = precise_time_ms();
@ -1089,13 +1048,7 @@ fn http_network_fetch(request: Rc<Request>,
let pipeline_id = request.pipeline_id.get(); let pipeline_id = request.pipeline_id.get();
let (res, msg) = match wrapped_response { let (res, msg) = match wrapped_response {
Ok(wrapped_response) => wrapped_response, Ok(wrapped_response) => wrapped_response,
Err(error) => { Err(error) => return Response::network_error(error),
let error = match error.error {
LoadErrorType::Ssl { reason } => NetworkError::SslValidation(error.url, reason),
e => NetworkError::Internal(e.description().to_owned())
};
return Response::network_error(error);
}
}; };
let mut response = Response::new(url.clone()); let mut response = Response::new(url.clone());