Bug 1325876 - 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:
Sean
2024-12-18 15:54:19 +00:00
parent b44e64d197
commit 7475fefd84
4 changed files with 61 additions and 5 deletions

View File

@@ -1667,16 +1667,30 @@ void Document::GetNetErrorInfo(NetErrorInfo& aInfo, ErrorResult& aRv) {
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;
rv = mFailedChannel->GetSecurityInfo(getter_AddRefs(tsi));
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(rv);
return;
}
if (NS_WARN_IF(!tsi)) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
nsresult channelStatus;
rv = mFailedChannel->GetStatus(&channelStatus);
@@ -1686,6 +1700,12 @@ void Document::GetNetErrorInfo(NetErrorInfo& aInfo, ErrorResult& aRv) {
}
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
(void)tsi->GetErrorCodeString(aInfo.mErrorCodeString);
if (aInfo.mErrorCodeString.IsEmpty()) {