Avoid NullReferenceException on 401 Unauthorized#2561
Conversation
We frequently experience NullReferenceExceptions in our logging registered by the first chance exception handler. It is caused by `intakeResponse` being not null: Accepted = 0, Errors = null, and then evaluating `intakeResponse.Errors.Count` triggering an error. Environment: Unauthorized 401 on https://53b082e7cfeb4d9a9c117371xxxxxxxx.apm.eu-west-1.aws.cloud.es.io/intake/v2/events The payload returned is: ```json {"error":"authentication failed"}\n ``` So an improvement might be to also deserialize this JSON format.
|
💚 CLA has been signed |
|
👋 @monty241 Thanks a lot for your contribution! It may take some time before we review a PR, so even if you don’t see activity for some time, it does not mean that we have forgotten about it. Every once in a while we go through a process of prioritization, after which we are focussing on the tasks that were planned for the upcoming milestone. The prioritization status is typically reflected through the PR labels. It could be pending triage, a candidate for a future milestone, or have a target milestone set to it. |
Signed twice now, but the site seems broken ( |
stevejgordon
left a comment
There was a problem hiding this comment.
Thanks for finding this and submitting the fix.
|
run docs-build |
JeremyBessonElastic
left a comment
There was a problem hiding this comment.
LGTM
Remark:
It should be enough:
if (intakeResponse?.Errors?.Count > 0)

We frequently experience NullReferenceExceptions in our logging registered by the first chance exception handler.
It is caused by
intakeResponsebeing not null: Accepted = 0, Errors = null, and then evaluatingintakeResponse.Errors.Counttriggering an error.Environment:
Unauthorized 401 on https://53b082e7cfeb4d9a9c117371xxxxxxxx.apm.eu-west-1.aws.cloud.es.io/intake/v2/events
The payload returned is:
{"error":"authentication failed"}\nSo an improvement might be to also deserialize this JSON format.