Home > Enterprise >  Objectify - make error in transaction propagate to end user - don't retry, throw error
Objectify - make error in transaction propagate to end user - don't retry, throw error

Time:07-23

How can I make it so that if there is an error in a transaction (such as a ConcurrentModificationException error), the error is propagated to the end user? So instead of retrying, it will just throw an error in the endpoint.

For example if I have an endpoint with a transaction like this:

ofy().transact(new Runnable() {
    @Override
    public void run() {
        // Load an entity, update some values and save it
    }
});

And the entity has too much contention on it, the endpoint will throw an exception to the end user.

A use case might be a user trying to make a credit card purchase but there is some sort of error in the transaction. I want to tell the user "We had a server error, please try again." - so the end user can know for certain that something completed or not.

Can I somehow wrap this in a try-catch and then throw an error? Or what is the best way to do it? Thanks.

CodePudding user response:

Looks like you'll want to transactNew (https://www.javadoc.io/doc/com.googlecode.objectify/objectify/6.0/com/googlecode/objectify/Objectify.html#transactNew-int-com.googlecode.objectify.Work-) to avoid retries.

  • Related