Skip to content

Commit

Permalink
Improve page load error information
Browse files Browse the repository at this point in the history
Fixes servo#8640.

This commit adds a neterror page that displays really really basic
information about what went wrong with your request, which is an
improvement over the current state of blank page.

It also fixes the problem of certificate validation errors not
triggering the cert error page, since for some reason the function
string seems to have turned lowercase.
  • Loading branch information
johannhof committed Jul 21, 2016
1 parent 46db988 commit 8e3593a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/net/http_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ fn is_cert_verify_error(error: &OpensslError) -> bool {
match error {
&OpensslError::UnknownError { ref library, ref function, ref reason } => {
library == "SSL routines" &&
function == "SSL3_GET_SERVER_CERTIFICATE" &&
function.to_uppercase() == "SSL3_GET_SERVER_CERTIFICATE" &&
reason == "certificate verify failed"
}
}
Expand Down
17 changes: 14 additions & 3 deletions components/script/dom/servohtmlparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,24 @@ impl AsyncResponseListener for ParserContext {
Some(parser) => parser.root(),
None => return,
};
parser.r().document().finish_load(LoadType::PageSource(self.url.clone()));

if let Err(err) = status {
debug!("Failed to load page URL {}, error: {:?}", self.url, err);
if let Err(NetworkError::Internal(ref reason)) = status {
// Show an error page for network errors,
// certificate errors are handled earlier.
self.is_synthesized_document = true;
let parser = parser.r();
let page_bytes = read_resource_file("neterror.html").unwrap();
let page = String::from_utf8(page_bytes).unwrap();
let page = page.replace("${reason}", reason);
parser.pending_input().borrow_mut().push(page);
parser.parse_sync();
} else if let Err(err) = status {
// TODO(Savago): we should send a notification to callers #5463.
debug!("Failed to load page URL {}, error: {:?}", self.url, err);
}

parser.r().document().finish_load(LoadType::PageSource(self.url.clone()));

parser.r().last_chunk_received().set(true);
if !parser.r().is_suspended() {
parser.r().parse_sync();
Expand Down
8 changes: 8 additions & 0 deletions resources/neterror.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Error loading page</title>
</head>
<body>
<p>Could not load the requested page: ${reason}</p>
</body>
</html>

0 comments on commit 8e3593a

Please sign in to comment.