# Handle Batch Connection Error

**URL:** <https://forum.weaviate.io/t/handle-batch-connection-error/1077>\
**Category:** Support\
**Tags:** developer-experience\
**Created:** [December 8, 2023, 1:06pm UTC](https://forum.weaviate.io/t/handle-batch-connection-error/1077 "2023-12-08T13:06:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dharanish](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dharanish/32/659_2.png) [@Dharanish](https://forum.weaviate.io/u/Dharanish)\
**Post date:** [December 8, 2023, 1:06pm UTC](https://forum.weaviate.io/t/handle-batch-connection-error/1077/1 "2023-12-08T13:06:38Z")

</div>

While Batch Insertion of data, shows Batch Connection Error due to network error and retries some time . If I try to catch that Exception ,after catched It shows retries. I need to handle Exception after all retries are exhausted how to achieve this.

def insert(class\_,obj\_count):  
vector\_val = [[random.random() for \_ in range(128)] for \_ in range(obj\_count)]  
start = time.time()

```
with client.batch as batch: # automatically calls flush()
    for id_, vec in enumerate(vector_val):
        data_obj = {
            "unique_id": id_
            }
        batch.add_data_object(
                data_obj, 
                class_, 
            vector=vec 
            # generate_uuid('Sample',doc), # if not provided, it generates automatically
            )

    print(time.time() - start)
    print(f"Finished importing data for {class_} Object Count :{obj_count}")

```

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [December 11, 2023, 10:09pm UTC](https://forum.weaviate.io/t/handle-batch-connection-error/1077/2 "2023-12-11T22:09:21Z")

</div>

Hi Dharanish!

Check this for error handling in batch imports:

> **[REST - /v1/batch | Weaviate - Vector Database](https://weaviate.io/developers/weaviate/api/rest/batch#error-handling)**
>
> Batch create objects

Tip: If you want to force an error, you can insert an object with 2 dimensions, then a second one with 3 dimensions.

Check this issue here for more on error handling:

> <https://github.com/weaviate/weaviate/issues/3818>
>
> \### How to reproduce this bug?
> 
> (Note: I'm encountering this issue using the p…ython client, so I wasn't sure if this repository or the python client one was preferred - however as it is documentation related I've put it here. Let me know if I should move it.)
> 
> I want to ensure that I can detect if a batch delete has been successful - so checking the documentation...
> 
> Under the \*\*Error handling\*\* section on the \*\*References: API \> RESTful API \> REST - /v1/batch\*\* page, the code in the \`check\_batch\_result\` has the following:
> 
> \`\`\`
> if results is not None:
> for result in results:
> if 'result' in result and 'errors' in result\['result'\]:
> if 'error' in result\['result'\]\['errors'\]:
> print(result\['result'\]\['errors'\]\['error'\])
> \`\`\`
> 
> This code was causing an exception on the third line where it was looking for 'errors' in result\['result'\].
> 
> I believe there's an \`objects\` element under the \`results\` element and that each of those object elements has an \`error\` element.
> 
> As I'm not sure how to cause an error in order to test for it I've updated the code, which runs, but I haven't been able to cause an error to test it.
> 
> \`\`\`
> if results is not None:
> for result in results:
> if result == 'results':
> if results\["results"\]\["objects"\] is not None:
> for object in results\["results"\]\["objects"\]:
> if "error" in object and object\["error"\] is not None:
> print(object\['error'\])
> \`\`\`
> 
> \### What is the expected behavior?
> 
> Any error messages are printed.
> 
> \### What is the actual behavior?
> 
> An exception occurs on the third line.
> 
> \### Supporting information
> 
> \_No response\_
> 
> \### Server Version
> 
> 1.21.2
> 
> \### Code of Conduct
> 
> \- \[X\] I have read and agree to the Weaviate's \[Contributor Guide\](https://weaviate.io/developers/contributor-guide) and \[Code of Conduct\](https://weaviate.io/service/code-of-conduct)
