Commit 524b14d5 authored by Douglas Creager's avatar Douglas Creager Committed by Commit Bot

NEL: Report `unknown` errors

If a request fails with a net::Error code that we don't have an explicit
NEL standard `type` value for, we still want to generate a NEL report.
The standard provides an `unknown` type for these errors.

Change-Id: If4c0ab3bf4052cec9224dfd7053e1ca500b1b5dc
Reviewed-on: https://chromium-review.googlesource.com/c/1329351Reviewed-by: default avatarMisha Efimov <mef@chromium.org>
Commit-Queue: Douglas Creager <dcreager@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607825}
parent 20b9700c
......@@ -113,17 +113,18 @@ const struct {
// TODO(juliatuttle): Surely there are more errors we want here.
};
bool GetPhaseAndTypeFromNetError(Error error,
void GetPhaseAndTypeFromNetError(Error error,
std::string* phase_out,
std::string* type_out) {
for (size_t i = 0; i < arraysize(kErrorTypes); ++i) {
if (kErrorTypes[i].error == error) {
*phase_out = kErrorTypes[i].phase;
*type_out = kErrorTypes[i].type;
return true;
return;
}
}
return false;
*phase_out = IsCertificateError(error) ? kConnectionPhase : kApplicationPhase;
*type_out = "unknown";
}
bool IsHttpError(const NetworkErrorLoggingService::RequestDetails& request) {
......@@ -238,10 +239,7 @@ class NetworkErrorLoggingServiceImpl : public NetworkErrorLoggingService {
std::string phase_string;
std::string type_string;
if (!GetPhaseAndTypeFromNetError(type, &phase_string, &type_string)) {
RecordRequestOutcome(RequestOutcome::DISCARDED_UNMAPPED_ERROR);
return;
}
GetPhaseAndTypeFromNetError(type, &phase_string, &type_string);
if (IsHttpError(details)) {
phase_string = kApplicationPhase;
......
......@@ -322,6 +322,43 @@ TEST_F(NetworkErrorLoggingServiceTest, FailureReportQueued) {
NetworkErrorLoggingService::kTypeKey);
}
TEST_F(NetworkErrorLoggingServiceTest, UnknownFailureReportQueued) {
static const std::string kHeaderFailureFraction1 =
"{\"report_to\":\"group\",\"max_age\":86400,\"failure_fraction\":1.0}";
service()->OnHeader(kOrigin_, kServerIP_, kHeaderFailureFraction1);
// This error code happens to not be mapped to a NEL report `type` field
// value.
service()->OnRequest(MakeRequestDetails(kUrl_, ERR_FILE_NO_SPACE));
ASSERT_EQ(1u, reports().size());
const base::DictionaryValue* body;
ASSERT_TRUE(reports()[0].body->GetAsDictionary(&body));
base::ExpectDictStringValue("application", *body,
NetworkErrorLoggingService::kPhaseKey);
base::ExpectDictStringValue("unknown", *body,
NetworkErrorLoggingService::kTypeKey);
}
TEST_F(NetworkErrorLoggingServiceTest, UnknownCertFailureReportQueued) {
static const std::string kHeaderFailureFraction1 =
"{\"report_to\":\"group\",\"max_age\":86400,\"failure_fraction\":1.0}";
service()->OnHeader(kOrigin_, kServerIP_, kHeaderFailureFraction1);
// This error code happens to not be mapped to a NEL report `type` field
// value. Because it's a certificate error, we'll set the `phase` to be
// `connection`.
service()->OnRequest(MakeRequestDetails(kUrl_, ERR_CERT_NON_UNIQUE_NAME));
ASSERT_EQ(1u, reports().size());
const base::DictionaryValue* body;
ASSERT_TRUE(reports()[0].body->GetAsDictionary(&body));
base::ExpectDictStringValue("connection", *body,
NetworkErrorLoggingService::kPhaseKey);
base::ExpectDictStringValue("unknown", *body,
NetworkErrorLoggingService::kTypeKey);
}
TEST_F(NetworkErrorLoggingServiceTest, HttpErrorReportQueued) {
static const std::string kHeaderFailureFraction1 =
"{\"report_to\":\"group\",\"max_age\":86400,\"failure_fraction\":1.0}";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment