As covered in the documentation, Couchbase intentionally returns TMPFAIL in temporary out of memory situations. This is one thing that is intentionally different in Couchbase compared to traditional databases and comes from our memcached history.
The philosophy here is to always be fast and let the application developer decide whether or not to redo the operation given that the cluster can’t service the operation at the moment.
So, what I’d recommend is adjusting the code to do an exponential backoff and retry with a do-while loop or something similar. The documentation covers this in the Error Handling section on Retry with delay.