# Java API Client Bulk Response Error Handling

**URL:** <https://discuss.elastic.co/t/java-api-client-bulk-response-error-handling/345794>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [October 26, 2023, 9:49am UTC](https://discuss.elastic.co/t/java-api-client-bulk-response-error-handling/345794 "2023-10-26T09:49:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravneet21](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ravneet21/32/122023_2.png) [@ravneet21](https://discuss.elastic.co/u/ravneet21)\
**Post date:** [October 26, 2023, 9:49am UTC](https://discuss.elastic.co/t/java-api-client-bulk-response-error-handling/345794/1 "2023-10-26T09:49:30Z")

</div>

Hi All,  
While migrating from Elastic HighLevelRestClient to bnew Java API Client, we are facing issues in handling error scenarios in BulkResponse.  
Earlier in HLRC, in BulkItemResponse, there was Failure type field, which contained RestStatus which is an enum of all the HTTP status codes. In Java API Client, we have BulkResponseItem, which has status(int) and result(string) fields, but there is no such mapping of all the rest statuses as earlier.  
How should that be handled?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 26, 2023, 1:20pm UTC](https://discuss.elastic.co/t/java-api-client-bulk-response-error-handling/345794/2 "2023-10-26T13:20:34Z")

</div>

Welcome!

I guess you could reuse this class in your code I believe:

> <https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/rest/RestStatus.java>

And call this method:

> <https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/rest/RestStatus.java#L524-L526>

I'm normally just using the int value on my side. Like

```
if (status >= 400) { 
  // Do something
}

```

Does this help?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 23, 2023, 1:21pm UTC](https://discuss.elastic.co/t/java-api-client-bulk-response-error-handling/345794/3 "2023-11-23T13:21:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
