@@ -164,11 +164,35 @@ public override bool NodePredicate(Node node) =>
164164 /// We consider all status codes >= 200 and < 300 valid by default.
165165 /// Elasticsearch might return 404 for valid responses in some cases (e.g. `GET /my-index/_doc/missing-doc-id`) but also for actual error cases like
166166 /// missing endpoints, missing indices (e.g. `GET /missing-index/_mapping`), etc.
167- /// The 404 case is handled on a per-request basis (see <see cref="ElasticsearchResponseHelper. IsValidResponse"/> for details).
167+ /// The 404 case is handled on a per-request basis (see <see cref="IsValidResponse(ApiCallDetails) "/> for details).
168168 /// </remarks>
169169 public override bool HttpStatusCodeClassifier ( HttpMethod method , int statusCode ) =>
170170 statusCode is >= 200 and < 300 ;
171171
172+ /// <inheritdoc cref="ProductRegistration.IsValidResponse(ApiCallDetails)"/>
173+ /// <remarks>
174+ /// A response is valid when:
175+ /// <list type="bullet">
176+ /// <item>The content-type matches what the caller asked for.</item>
177+ /// <item>For 404 responses: there is no extracted Elasticsearch server error
178+ /// (404s without an error body — e.g. <c>GET /my-index/_doc/missing-doc-id</c> — represent
179+ /// a legitimate "missing entity" rather than a failure).</item>
180+ /// <item>Otherwise: the status code is in the success range (or explicitly allowed via
181+ /// <see cref="IRequestConfiguration.AllowedStatusCodes"/>).</item>
182+ /// </list>
183+ /// </remarks>
184+ public override bool IsValidResponse ( ApiCallDetails ? details )
185+ {
186+ if ( details is null || ! details . HasExpectedContentType )
187+ return false ;
188+
189+ var serverError = details . ProductError as ElasticsearchServerError ;
190+ if ( details . HttpStatusCode is 404 )
191+ return ! serverError ? . HasError ( ) ?? true ;
192+
193+ return details . HasSuccessfulStatusCode ;
194+ }
195+
172196 /// <inheritdoc cref="ProductRegistration.TryGetServerErrorReason{TResponse}"/>>
173197 public override bool TryGetServerErrorReason < TResponse > ( TResponse response , out string ? reason )
174198 {
0 commit comments