Bug 1890028 - Display Server Error message when server returns HTTP 500 and unusual content-type r=kershaw,fluent-reviewers,necko-reviewers,flod

Differential Revision: https://phabricator.services.mozilla.com/D216978
This commit is contained in:
Sean
2024-08-07 13:31:02 +00:00
parent 5d442069c0
commit 17f89e2207
11 changed files with 72 additions and 2 deletions

View File

@@ -53,6 +53,11 @@ support-files = [
["browser_aboutNetError_native_fallback.js"]
skip-if = ["socketprocess_networking"]
["browser_aboutNetError_server_error.js"]
support-files = [
"server_error.sjs",
]
["browser_aboutNetError_trr.js"]
skip-if = ["socketprocess_networking"]

View File

@@ -0,0 +1,45 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const SERVER_ERROR_PAGE =
"https://example.com/browser/browser/base/content/test/about/server_error.sjs";
add_task(async function test_serverError() {
let browser;
let pageLoaded;
await BrowserTestUtils.openNewForegroundTab(
gBrowser,
() => {
gBrowser.selectedTab = BrowserTestUtils.addTab(
gBrowser,
SERVER_ERROR_PAGE
);
browser = gBrowser.selectedBrowser;
pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
},
false
);
info("Loading and waiting for the net error");
await pageLoaded;
await SpecialPowers.spawn(browser, [], function () {
const doc = content.document;
ok(
doc.documentURI.startsWith("about:neterror"),
"Should be showing error page"
);
const titleEl = doc.querySelector(".title-text");
const actualDataL10nID = titleEl.getAttribute("data-l10n-id");
is(
actualDataL10nID,
"serverError-title",
"Correct error page title is set"
);
});
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});

View File

@@ -0,0 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
function handleRequest(request, response) {
response.setStatusLine(request.httpVersion, 500, "Internal Server Error");
response.setHeader("Content-Type", "application/octet-stream", false);
}

View File

@@ -5,6 +5,8 @@
malformedURI2=Please check that the URL is correct and try again.
fileNotFound=Firefox cant find the file at %S.
fileAccessDenied=The file at %S is not readable.
# %S is replaced by the uri host
serverError=%S might have a temporary problem or it could have moved.
dnsNotFound2=We cant connect to the server at %S.
unknownProtocolFound=Firefox doesnt know how to open this address, because one of the following protocols (%S) isnt associated with any program or is not allowed in this context.
connectionFailure=Firefox cant establish a connection to the server at %S.

View File

@@ -3360,6 +3360,9 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,
nestedURI = do_QueryInterface(tempURI);
}
error = "unknownProtocolFound";
} else if (NS_ERROR_NET_ERROR_RESPONSE == aError) {
NS_ENSURE_ARG_POINTER(aURI);
error = "serverError";
} else if (NS_ERROR_FILE_NOT_FOUND == aError) {
NS_ENSURE_ARG_POINTER(aURI);
error = "fileNotFound";
@@ -6146,6 +6149,7 @@ nsresult nsDocShell::FilterStatusForErrorPage(
if (aStatus == NS_ERROR_NET_TIMEOUT ||
aStatus == NS_ERROR_NET_TIMEOUT_EXTERNAL ||
aStatus == NS_ERROR_NET_ERROR_RESPONSE ||
aStatus == NS_ERROR_PROXY_GATEWAY_TIMEOUT ||
aStatus == NS_ERROR_REDIRECT_LOOP ||
aStatus == NS_ERROR_UNKNOWN_SOCKET_TYPE ||

View File

@@ -157,6 +157,7 @@ XPC_MSG_DEF(NS_ERROR_NET_TIMEOUT_EXTERNAL , "The request has been canc
XPC_MSG_DEF(NS_ERROR_OFFLINE , "The requested action could not be completed in the offline state")
XPC_MSG_DEF(NS_ERROR_PORT_ACCESS_NOT_ALLOWED , "Establishing a connection to an unsafe or otherwise banned port was prohibited")
XPC_MSG_DEF(NS_ERROR_NET_RESET , "The connection was established, but no data was ever received")
XPC_MSG_DEF(NS_ERROR_NET_ERROR_RESPONSE , "The connection was established, but the browser received an error response from the server")
XPC_MSG_DEF(NS_ERROR_NET_INTERRUPT , "The connection was established, but the data transfer was interrupted")
XPC_MSG_DEF(NS_ERROR_NET_PARTIAL_TRANSFER , "A transfer was only partially done when it completed")
XPC_MSG_DEF(NS_ERROR_NET_HTTP3_PROTOCOL_ERROR , "There has been a http3 protocol error")

View File

@@ -42,6 +42,7 @@ const KNOWN_ERROR_TITLE_IDS = new Set([
"unsafeContentType-title",
"netReset-title",
"netTimeout-title",
"serverError-title",
"unknownProtocolFound-title",
"proxyConnectFailure-title",
"proxyResolveFailure-title",
@@ -745,6 +746,7 @@ function getNetErrorDescParts() {
case "netInterrupt":
case "netReset":
case "netTimeout":
case "serverError":
return [
["li", "neterror-load-error-try-again"],
["li", "neterror-load-error-connection"],

View File

@@ -125,6 +125,7 @@ contentEncodingError-title = Content Encoding Error
unsafeContentType-title = Unsafe File Type
netReset-title = The connection was reset
netTimeout-title = The connection has timed out
serverError-title = Looks like theres a problem with this site
unknownProtocolFound-title = The address wasnt understood
proxyConnectFailure-title = The proxy server is refusing connections
proxyResolveFailure-title = Unable to find the proxy server

View File

@@ -63,6 +63,7 @@ ID01:
- unsafeContentType-title
- netReset-title
- netTimeout-title
- serverError-title
- unknownProtocolFound-title
- proxyConnectFailure-title
- proxyResolveFailure-title

View File

@@ -444,9 +444,9 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest* request) {
rv = httpChannel->GetRequestSucceeded(&requestSucceeded);
if (NS_FAILED(rv) || !requestSucceeded) {
LOG(
(" Returning NS_ERROR_FILE_NOT_FOUND from "
(" Returning NS_ERROR_NET_ERROR_RESPONSE from "
"nsDocumentOpenInfo::DispatchContent due to failed HTTP response"));
return NS_ERROR_FILE_NOT_FOUND;
return NS_ERROR_NET_ERROR_RESPONSE;
}
}

View File

@@ -325,6 +325,8 @@ with modules["NETWORK"]:
errors["NS_ERROR_PORT_ACCESS_NOT_ALLOWED"] = FAILURE(19)
# The connection was established, but no data was ever received.
errors["NS_ERROR_NET_RESET"] = FAILURE(20)
# The connection was established, but browser received an error response from the server
errors["NS_ERROR_NET_ERROR_RESPONSE"] = FAILURE(35)
# The connection was established, but the data transfer was interrupted.
errors["NS_ERROR_NET_INTERRUPT"] = FAILURE(71)
# The connection attempt to a proxy failed.