Handling gmail errors.

This commit is contained in:
Burak Kaan Köse
2024-08-29 22:43:27 +02:00
parent 4dac160619
commit 3016f70349

View File

@@ -793,6 +793,8 @@ namespace Wino.Core.Synchronizers
var bundleRequestCount = bundle.Count(); var bundleRequestCount = bundle.Count();
var bundleTasks = new List<Task>();
for (int k = 0; k < bundleRequestCount; k++) for (int k = 0; k < bundleRequestCount; k++)
{ {
var requestBundle = bundle.ElementAt(k); var requestBundle = bundle.ElementAt(k);
@@ -802,37 +804,40 @@ namespace Wino.Core.Synchronizers
request.ApplyUIChanges(); request.ApplyUIChanges();
// TODO: Queue is synchronous. Create a task bucket to await all processing. nativeBatchRequest.Queue<object>(nativeRequest, (content, error, index, message)
nativeBatchRequest.Queue<object>(nativeRequest, async (content, error, index, message) => bundleTasks.Add(ProcessSingleNativeRequestResponseAsync(requestBundle, error, message, cancellationToken)));
=> await ProcessSingleNativeRequestResponseAsync(requestBundle, error, message, cancellationToken).ConfigureAwait(false));
} }
await nativeBatchRequest.ExecuteAsync(cancellationToken).ConfigureAwait(false); await nativeBatchRequest.ExecuteAsync(cancellationToken).ConfigureAwait(false);
await Task.WhenAll(bundleTasks);
} }
} }
private void ProcessGmailRequestError(RequestError error) private void ProcessGmailRequestError(RequestError error, IRequestBundle<IClientServiceRequest> bundle)
{ {
if (error == null) return; if (error == null) return;
// OutOfMemoryException is a known bug in Gmail SDK. // OutOfMemoryException is a known bug in Gmail SDK.
if (error.Code == 0) if (error.Code == 0)
{ {
bundle?.Request.RevertUIChanges();
throw new OutOfMemoryException(error.Message); throw new OutOfMemoryException(error.Message);
} }
// Entity not found. // Entity not found.
if (error.Code == 404) if (error.Code == 404)
{ {
bundle?.Request.RevertUIChanges();
throw new SynchronizerEntityNotFoundException(error.Message); throw new SynchronizerEntityNotFoundException(error.Message);
} }
if (!string.IsNullOrEmpty(error.Message)) if (!string.IsNullOrEmpty(error.Message))
{ {
bundle?.Request.RevertUIChanges();
error.Errors?.ForEach(error => _logger.Error("Unknown Gmail SDK error for {Name}\n{Error}", Account.Name, error)); error.Errors?.ForEach(error => _logger.Error("Unknown Gmail SDK error for {Name}\n{Error}", Account.Name, error));
// TODO: Debug throw new SynchronizerException(error.Message);
// throw new SynchronizerException(error.Message);
} }
} }
@@ -851,7 +856,7 @@ namespace Wino.Core.Synchronizers
{ {
try try
{ {
ProcessGmailRequestError(error); ProcessGmailRequestError(error, null);
} }
catch (OutOfMemoryException) catch (OutOfMemoryException)
{ {
@@ -900,7 +905,7 @@ namespace Wino.Core.Synchronizers
HttpResponseMessage httpResponseMessage, HttpResponseMessage httpResponseMessage,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
ProcessGmailRequestError(error); ProcessGmailRequestError(error, bundle);
if (bundle is HttpRequestBundle<IClientServiceRequest, Message> messageBundle) if (bundle is HttpRequestBundle<IClientServiceRequest, Message> messageBundle)
{ {