Java exception when creating multiple permissions in Google Drive docs

In our application, we need to provide multiple files to multiple users using Google Drive.

We use the batch processing provided by the java client library of the Google Drive api.

This is already done during production, but we get a lot of obscure exceptions from the Google Drive api:

Internal Error. User message: "An internal error has occurred which prevented the sharing of these item(s): "

enter image description here

We handle exceptions and try exponentially again, but these errors cause large delays in the flow and usability of this application.

What is the reason for these exceptions? How to avoid this?

It would be very helpful if we knew what happens when these exceptions occur, so we can avoid this.

Additional Information: Each batch contains 100 permission operations for different files. A batch operation is called every minute.

The code:

String fileId = "1sTWaJ_j7PkjzaBWtNc3IzovK5hQf21FbOw9yLeeLPNQ";
JsonBatchCallback<Permission> callback = new JsonBatchCallback<Permission>() 
{
    @Override
    public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders)
        throws IOException {
        System.err.println(e.getMessage());
    }

    @Override
    public void onSuccess(Permission permission, HttpHeaders responseHeaders) throws IOException {
        System.out.println("Permission ID: " + permission.getId());
    }
};

BatchRequest batch = driveService.batch();

for(String email : emails) {
    Permission userPermission = new Permission().setType("user").setRole("reader").setEmailAddress(email);
    driveService.permissions().create(fileId, userPermission).setSendNotificationEmail(false).setFields("id").queue(batch, callback);
}

batch.execute();

variable emails contain 100 lines of email.

+4
source share
1 answer
    {
    "code" : 500,
    "errors" : [ {
    "domain" : "global",
    "message" : "Internal Error. User message: "An internal                                                     error has occurred which prevented the sharing of these item(s): fileame"",
   "reason" : "internalError"
    } ],
  "message" : "Internal Error. User message: "An internal error has occurred which prevented the sharing of these item(s): filename""
    }

It is mainly flood protection. Common Recommendation - Implementing Exponential Delay

- , . , . , , , , , .

, , , .

, , , . Yup . . , , , 100 , , , , , , , -, .

, , 10 , . , , , . , .

+1

Source: https://habr.com/ru/post/1672989/


All Articles