Influx write api catch exceptions

26 views Asked by At

Context

I have a project which uses influxdb-client-java version 7.0.0. I am writing points using the WriteApi which starts a background thread to send data to the influxdb instance.

My Problem

I want to catch the UnauthorizedException to act upon it.

Question

Can I register an exception handler somewhere or how could I achive that?

I have searched online but could not find any useful documentation.

1

There are 1 answers

0
Jannik On

I found a way how to achieve it. The WriteApi has a listenEvents method which you can use for it. An example:

final var writeApi = client.makeWriteApi(writeOptions);
     writeApi.listenEvents(WriteErrorEvent.class, event -> {
     if (event.getThrowable() instanceof UnauthorizedException) {
          log.error("Could not send data to influx. The provided influx token is either wrong or does not has the write permission granted.");
          System.exit(-1);
     }
});