How to handle the errors may be use case specific if you want/need to retry.
You can take a look at how Logstash implements retry here: https://github.com/logstash-plugins/logstash-output-elasticsearch/blob/master/lib/logstash/outputs/elasticsearch/common.rb#L225
In summary Logstash retries anything that is not a 409 (conflict), 400(bad request) or 404 (missing) . Logstash also implements an incremental back off when retrying with continued failures which helps keep things healthy especially when Elasticsearch is pushing back with 429 (too many requests).
This is pretty good general retry policy. However, if for example, you know all requests should authorized, you may not want to retry 401 or 403s.