Bug 1938947 - Expose responseStatus and responseStatusText for about:neterror r=necko-reviewers,fluent-reviewers,bolsson,kershaw,webidl,saschanaz
Differential Revision: https://phabricator.services.mozilla.com/D223417
This commit is contained in:
@@ -39,6 +39,14 @@ add_task(async function test_serverError() {
|
|||||||
"serverError-title",
|
"serverError-title",
|
||||||
"Correct error page title is set"
|
"Correct error page title is set"
|
||||||
);
|
);
|
||||||
|
const responseStatusLabel = doc.getElementById(
|
||||||
|
"response-status-label"
|
||||||
|
).textContent;
|
||||||
|
is(
|
||||||
|
responseStatusLabel,
|
||||||
|
"Error code: 500 Internal Server Error",
|
||||||
|
"Correct response status message is set"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||||
|
|||||||
@@ -1667,16 +1667,30 @@ void Document::GetNetErrorInfo(NetErrorInfo& aInfo, ErrorResult& aRv) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mFailedChannel));
|
||||||
|
|
||||||
|
// We don't throw even if httpChannel is null, we just keep responseStatus and
|
||||||
|
// responseStatusText empty
|
||||||
|
if (httpChannel) {
|
||||||
|
uint32_t responseStatus;
|
||||||
|
nsAutoCString responseStatusText;
|
||||||
|
rv = httpChannel->GetResponseStatus(&responseStatus);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
aInfo.mResponseStatus = responseStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = httpChannel->GetResponseStatusText(responseStatusText);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
aInfo.mResponseStatusText.AssignASCII(responseStatusText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsITransportSecurityInfo> tsi;
|
nsCOMPtr<nsITransportSecurityInfo> tsi;
|
||||||
rv = mFailedChannel->GetSecurityInfo(getter_AddRefs(tsi));
|
rv = mFailedChannel->GetSecurityInfo(getter_AddRefs(tsi));
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
aRv.Throw(rv);
|
aRv.Throw(rv);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (NS_WARN_IF(!tsi)) {
|
|
||||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult channelStatus;
|
nsresult channelStatus;
|
||||||
rv = mFailedChannel->GetStatus(&channelStatus);
|
rv = mFailedChannel->GetStatus(&channelStatus);
|
||||||
@@ -1686,6 +1700,12 @@ void Document::GetNetErrorInfo(NetErrorInfo& aInfo, ErrorResult& aRv) {
|
|||||||
}
|
}
|
||||||
aInfo.mChannelStatus = static_cast<uint32_t>(channelStatus);
|
aInfo.mChannelStatus = static_cast<uint32_t>(channelStatus);
|
||||||
|
|
||||||
|
// If nsITransportSecurityInfo is not set, simply keep the remaining fields
|
||||||
|
// empty (to make responseStatus and responseStatusText accessible).
|
||||||
|
if (!tsi) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TransportSecurityInfo::GetErrorCodeString always returns NS_OK
|
// TransportSecurityInfo::GetErrorCodeString always returns NS_OK
|
||||||
(void)tsi->GetErrorCodeString(aInfo.mErrorCodeString);
|
(void)tsi->GetErrorCodeString(aInfo.mErrorCodeString);
|
||||||
if (aInfo.mErrorCodeString.IsEmpty()) {
|
if (aInfo.mErrorCodeString.IsEmpty()) {
|
||||||
|
|||||||
@@ -12,4 +12,6 @@
|
|||||||
dictionary NetErrorInfo {
|
dictionary NetErrorInfo {
|
||||||
DOMString errorCodeString = "";
|
DOMString errorCodeString = "";
|
||||||
unsigned long channelStatus = 0;
|
unsigned long channelStatus = 0;
|
||||||
|
unsigned long responseStatus = 0;
|
||||||
|
DOMString responseStatusText = "";
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -265,6 +265,32 @@ function recordTRREventTelemetry(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setResponseStatus(shortDesc) {
|
||||||
|
let responseStatus;
|
||||||
|
let responseStatusText;
|
||||||
|
try {
|
||||||
|
const netErrorInfo = document.getNetErrorInfo();
|
||||||
|
responseStatus = netErrorInfo.responseStatus;
|
||||||
|
responseStatusText = netErrorInfo.responseStatusText;
|
||||||
|
} catch (ex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (responseStatus >= 400) {
|
||||||
|
let responseStatusLabel = document.createElement("p");
|
||||||
|
responseStatusLabel.id = "response-status-label"; // id for testing
|
||||||
|
document.l10n.setAttributes(
|
||||||
|
responseStatusLabel,
|
||||||
|
"neterror-response-status-code",
|
||||||
|
{
|
||||||
|
responsestatus: responseStatus,
|
||||||
|
responsestatustext: responseStatusText ?? "",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
shortDesc.appendChild(responseStatusLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function initPage() {
|
function initPage() {
|
||||||
// We show an offline support page in case of a system-wide error,
|
// We show an offline support page in case of a system-wide error,
|
||||||
// when a user cannot connect to the internet and access the SUMO website.
|
// when a user cannot connect to the internet and access the SUMO website.
|
||||||
@@ -595,6 +621,7 @@ function initPage() {
|
|||||||
setNetErrorMessageFromParts(longDesc, parts);
|
setNetErrorMessageFromParts(longDesc, parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setResponseStatus(shortDesc);
|
||||||
setNetErrorMessageFromCode();
|
setNetErrorMessageFromCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -824,7 +851,10 @@ function setNetErrorMessageFromCode() {
|
|||||||
try {
|
try {
|
||||||
errorCode = document.getNetErrorInfo().errorCodeString;
|
errorCode = document.getNetErrorInfo().errorCodeString;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// We don't have a securityInfo when this is for example a DNS error.
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!errorCode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -178,3 +178,8 @@ certerror-mitm-what-can-you-do-about-it-attack-sts = If you are not familiar wit
|
|||||||
certerror-what-should-i-do-bad-sts-cert-explanation = <b>{ $hostname }</b> has a security policy called HTTP Strict Transport Security (HSTS), which means that { -brand-short-name } can only connect to it securely. You can’t add an exception to visit this site.
|
certerror-what-should-i-do-bad-sts-cert-explanation = <b>{ $hostname }</b> has a security policy called HTTP Strict Transport Security (HSTS), which means that { -brand-short-name } can only connect to it securely. You can’t add an exception to visit this site.
|
||||||
|
|
||||||
cert-error-trust-certificate-transparency-what-can-you-do-about-it = Probably nothing, since it’s likely there’s a problem with the site itself.
|
cert-error-trust-certificate-transparency-what-can-you-do-about-it = Probably nothing, since it’s likely there’s a problem with the site itself.
|
||||||
|
|
||||||
|
# Variables:
|
||||||
|
# $responsestatus (string) - HTTP response status code (e.g., 500).
|
||||||
|
# $responsestatustext (string) - HTTP response status text (e.g., "Internal Server Error").
|
||||||
|
neterror-response-status-code = Error code: { $responsestatus } { $responsestatustext }
|
||||||
|
|||||||
Reference in New Issue
Block a user