1

Google Drive Realtime API has a nice set of errorTypes that you can listen for, so you can handle each case individually:

https://developers.google.com/drive/realtime/reference/gapi.drive.realtime.ErrorType

Unfortunately, this list doesn't include the DocumentClosed error. For some reason, that error is its own object in the API.

https://developers.google.com/drive/realtime/reference/gapi.drive.realtime.DocumentClosedError

For the life of me, I cannot figure out how to handle this error. I have an onError listener function set up on my realtime.load, but that only catches Errors, which are different than the DocumentClosedError.

Is there any way to handle/listen for this particular type of error? I have also tried document.addEventListener but that was a desperate attempt and didn't work

cranderveldt
  • 109
  • 9

2 Answers2

1

For anyone else wondering about this, it was related to binding between angular and google drive.

The document was closed for google but the angular binding were still there.

We handled this by intercepting the angular error based on this. http://odetocode.com/blogs/scott/archive/2014/04/21/better-error-handling-in-angularjs.aspx

notorange
  • 218
  • 2
  • 9
1

The DocumentClosedError is a different type of error as it is only thrown when you are accessing an invalid document. The only times that that Realtime Document should be invalid are: 1) after one of the fatal errors defined in ErrorType is handled by your error function, or 2)after you call .close() yourself on the document.

Tracking whether you hit one of these two conditions on the client and ensuring you don't access the Document afterwards is how to prevent the error from firing. Ideally if you get into a state where your document is closed, the app should teardown its references to the realtime models and reconnect to reduce the number places that you will throw exceptions.

TL;DR: If you're hitting DocumentClosedErrors you should change the way that you handle fatal errors defined in ErrorType.

Grant Watters
  • 660
  • 4
  • 16