Skip to content

Commit 5cf70a2

Browse files
committed
Don't expect Contet-Type header to exactly match application/json
InfluxDB seems to always include some other metadata in the `Content-Type` header separated by semicolons like `application/json; charset=utf-8`, and comparing the whole string with `application/json` will always fail, resulting in almost always useless warnings without any helpful information for the user what actually went wrong.
1 parent 2063d2b commit 5cf70a2

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

lib/perfdata/influxdbcommonwriter.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -493,31 +493,8 @@ void InfluxdbCommonWriter::FlushWQ()
493493
auto& response (parser.get());
494494

495495
if (response.result() != http::status::no_content) {
496-
Log(LogWarning, GetReflectionType()->GetName())
497-
<< "Unexpected response code: " << response.result();
498-
499-
auto& contentType (response[http::field::content_type]);
500-
if (contentType != "application/json") {
501-
Log(LogWarning, GetReflectionType()->GetName())
502-
<< "Unexpected Content-Type: " << contentType;
503-
return;
504-
}
505-
506-
Dictionary::Ptr jsonResponse;
507-
auto& body (response.body());
508-
509-
try {
510-
jsonResponse = JsonDecode(body);
511-
} catch (...) {
512-
Log(LogWarning, GetReflectionType()->GetName())
513-
<< "Unable to parse JSON response:\n" << body;
514-
return;
515-
}
516-
517-
String error = jsonResponse->Get("error");
518-
519496
Log(LogCritical, GetReflectionType()->GetName())
520-
<< "InfluxDB error message:\n" << error;
497+
<< "Unexpected response code: " << response.result() << ", InfluxDB error message:\n" << response.body();
521498
}
522499
}
523500

0 commit comments

Comments
 (0)