mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Remove LoadError.
This commit is contained in:
parent
c9370e04a5
commit
87979ef65e
1 changed files with 8 additions and 55 deletions
|
@ -40,7 +40,6 @@ use resource_thread::AuthCache;
|
|||
use servo_url::ServoUrl;
|
||||
use std::collections::HashSet;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::iter::FromIterator;
|
||||
use std::mem::swap;
|
||||
|
@ -129,7 +128,7 @@ struct NetworkHttpRequestFactory {
|
|||
|
||||
impl NetworkHttpRequestFactory {
|
||||
fn create(&self, url: ServoUrl, method: Method, headers: Headers)
|
||||
-> Result<HyperRequest<Fresh>, LoadError> {
|
||||
-> Result<HyperRequest<Fresh>, NetworkError> {
|
||||
let connection = HyperRequest::with_connector(method,
|
||||
url.clone().into_url().unwrap(),
|
||||
&*self.connector);
|
||||
|
@ -152,15 +151,14 @@ impl NetworkHttpRequestFactory {
|
|||
}
|
||||
|
||||
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 {
|
||||
Ok(req) => req,
|
||||
Err(e) => return Err(
|
||||
LoadError::new(url, LoadErrorType::Connection { reason: e.description().to_owned() })),
|
||||
Err(e) => return Err(NetworkError::Internal(e.description().to_owned())),
|
||||
};
|
||||
*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) {
|
||||
if headers.has::<AcceptEncoding>() {
|
||||
return
|
||||
|
@ -444,7 +406,7 @@ fn obtain_response(request_factory: &NetworkHttpRequestFactory,
|
|||
iters: u32,
|
||||
request_id: Option<&str>,
|
||||
is_xhr: bool)
|
||||
-> Result<(WrappedHttpResponse, Option<ChromeToDevtoolsControlMsg>), LoadError> {
|
||||
-> Result<(WrappedHttpResponse, Option<ChromeToDevtoolsControlMsg>), NetworkError> {
|
||||
let null_data = None;
|
||||
let connection_url = replace_hosts(&url);
|
||||
|
||||
|
@ -495,14 +457,12 @@ fn obtain_response(request_factory: &NetworkHttpRequestFactory,
|
|||
|
||||
let mut request_writer = match request.start() {
|
||||
Ok(streaming) => streaming,
|
||||
Err(e) => return Err(LoadError::new(connection_url,
|
||||
LoadErrorType::Connection { reason: e.description().to_owned() })),
|
||||
Err(e) => return Err(NetworkError::Internal(e.description().to_owned())),
|
||||
};
|
||||
|
||||
if let Some(ref data) = *request_body {
|
||||
if let Err(e) = request_writer.write_all(&data) {
|
||||
return Err(LoadError::new(connection_url,
|
||||
LoadErrorType::Connection { reason: e.description().to_owned() }))
|
||||
return Err(NetworkError::Internal(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());
|
||||
continue;
|
||||
},
|
||||
Err(e) => return Err(LoadError::new(connection_url,
|
||||
LoadErrorType::Connection { reason: e.description().to_owned() })),
|
||||
Err(e) => return Err(NetworkError::Internal(e.description().to_owned())),
|
||||
};
|
||||
|
||||
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 (res, msg) = match wrapped_response {
|
||||
Ok(wrapped_response) => wrapped_response,
|
||||
Err(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);
|
||||
}
|
||||
Err(error) => return Response::network_error(error),
|
||||
};
|
||||
|
||||
let mut response = Response::new(url.clone());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue