Add NetworkError::LoadCancelled variant.

This commit is contained in:
Corey Farwell 2016-04-27 00:23:21 -04:00
parent aa078a0780
commit 55c2f93740
4 changed files with 7 additions and 6 deletions

View file

@ -50,7 +50,7 @@ fn read_all(reader: &mut File, progress_chan: &ProgressSender, cancel_listener:
ReadStatus::EOF => return Ok(LoadResult::Finished),
}
}
let _ = progress_chan.send(Done(Err(NetworkError::Internal("load cancelled".to_owned()))));
let _ = progress_chan.send(Done(Err(NetworkError::LoadCancelled)));
Ok(LoadResult::Cancelled)
}
@ -92,7 +92,7 @@ pub fn factory(load_data: LoadData,
if cancel_listener.is_cancelled() {
if let Ok(progress_chan) = get_progress_chan(load_data, file_path,
senders, classifier, &[]) {
let _ = progress_chan.send(Done(Err(NetworkError::Internal("load cancelled".to_owned()))));
let _ = progress_chan.send(Done(Err(NetworkError::LoadCancelled)));
}
return;
}

View file

@ -160,6 +160,7 @@ fn load_for_consumer(load_data: LoadData,
LoadErrorType::Ssl { .. } => send_error(error.url.clone(),
NetworkError::SslValidation(error.url),
start_chan),
LoadErrorType::Cancelled => send_error(error.url, NetworkError::LoadCancelled, start_chan),
_ => send_error(error.url, NetworkError::Internal(error.error.description().to_owned()), start_chan)
}
}
@ -983,7 +984,7 @@ fn send_data<R: Read>(context: LoadContext,
loop {
if cancel_listener.is_cancelled() {
let _ = progress_chan.send(Done(Err(NetworkError::Internal("load cancelled".to_owned()))));
let _ = progress_chan.send(Done(Err(NetworkError::LoadCancelled)));
return;
}

View file

@ -437,9 +437,9 @@ pub enum ConstellationMsg {
/// Network errors that have to be exported out of the loaders
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize, HeapSizeOf)]
pub enum NetworkError {
/// Could be any of the internal errors, like unsupported scheme, load
/// cancellation, connection errors, etc.
/// Could be any of the internal errors, like unsupported scheme, connection errors, etc.
Internal(String),
LoadCancelled,
/// SSL validation error that has to be handled in the HTML parser
SslValidation(Url),
}

View file

@ -220,6 +220,6 @@ fn test_cancelled_listener() {
let _ = body_sender.send(body);
let response = receiver.recv().unwrap();
assert_eq!(response.progress_port.recv().unwrap(),
ProgressMsg::Done(Err(NetworkError::Internal("load cancelled".to_owned()))));
ProgressMsg::Done(Err(NetworkError::LoadCancelled)));
resource_thread.send(ControlMsg::Exit).unwrap();
}