Google.Apis.Email_Migration_v2



我正试图从每个UploadAsync方法调用中检索HttpStatusCode。我需要正确执行指数后退算法的状态代码,以重试失败的上传,在不重试上传时向用户显示错误消息,并报告上传成功。我不在乎它是如何接收的,只要它是干净的,并且不是从Exception.Message(字符串)属性中解析的,就像Tor Jonsson在下面提供的链接中建议的那样。

为了强制"错误请求错误[400]",我只是在MailResource.InsertMediaUpload的构造函数中提供了一个无效的用户密钥(电子邮件)。
例如MailResource.InsertMediaUpload(mailItem,)invalidEmail@domain.com",流,"message/rfc822")

问题

1) GoogleApiException.HttpStatusCode始终为0(不可用)。即使Exception.Message显示在括号中包含状态代码时也是如此。例如[400]
2) 找不到GoogleApiRequestException。

问题
1) 执行指数后退算法的最佳方式是什么
2) 在这种情况下,这是该物业的预期行为吗
3) GoogleApiRequestException是否仍然存在,如果存在,在哪里?

旁注:
我还注意到GoogleApiRequestException类不再与GoogleApiException类在同一个文件中。是否已将其移动到其他命名空间或删除?因为我想尝试捕获GoogleApiRequestException对象并获取其RequestError对象。

我为我的意思添加了两个diff的链接:

之前:http://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis/GoogleApiException.cs?r=a8e27790f8769c1d6aaae030bb46c79daa7cdbad

之后:http://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis/GoogleApiException.cs?r=d6f06e92d90b635c179013e2c287b42b82909c09

来源

我使用的是NuGet(1.6.0.8-beta)的最新二进制文件

我发现的唯一一个问题与我的问题有关:(只能发布两个链接…这是原始链接)stackoverflow.com/questions/18895306/httpstatuscode在使用google net api时未设置为异常

代码:(使用自定义记录器写入调试视图)

    public int Index; // Used to Id the process
    private void TryUpload(MailResource.InsertMediaUpload upload, out IUploadProgress uploadProgress, out bool retryUpload)
    {
        uploadProgress = null;
        retryUpload = false;
        CancellationToken token;
        try
        {
            uploadProgress = upload.UploadAsync(token).Result;
            if (uploadProgress.Exception != null)
            {
                _logger.WriteTrace("EXCEPTION!!! Type: {0}", uploadProgress.Exception.GetType().ToString()); // Remove:
                // *) Handle all of the various exceptions
                if (uploadProgress.Exception is JsonReaderException)
                {
                    JsonReaderException jreEx = uploadProgress.Exception as JsonReaderException;
                    _logger.WriteTrace("JsonReaderException-> Message: {0}", jreEx.Message);
                }
                if (uploadProgress.Exception is TokenResponseException)
                {
                    TokenErrorResponse trEx = uploadProgress as TokenErrorResponse;
                    _logger.WriteTrace("TokenErrorResponse-> Message: {0}", trEx.Error);
                }
                if (uploadProgress.Exception is HttpRequestValidationException)
                {
                    HttpRequestValidationException hrvEx = uploadProgress.Exception as HttpRequestValidationException;
                    _logger.WriteTrace("HttpRequestValidationException-> Message: {0}", hrvEx.Message);
                    _logger.WriteTrace("HttpRequestValidationException-> Status Code: {0}", hrvEx.GetHttpCode());
                }
                if (uploadProgress.Exception is GoogleApiException)
                {
                    GoogleApiException gApiEx = uploadProgress.Exception as GoogleApiException;
                    _logger.WriteTrace("GoogleApiException-> Message: {0}", gApiEx.Message);
                    _logger.WriteTrace("GoogleApiException-> Status Code: {0}", gApiEx.HttpStatusCode);
                }
            }
        }
        catch (Exception ex)
        {
            _logger.WriteTrace(ex, "An exception occured while uploading...");
        }
        finally
        {
            if (uploadProgress != null)
                _logger.WriteTrace("Upload Completed... Status: {0} Exception?: {1}", 
                    uploadProgress.Status, 
                    (uploadProgress.Exception == null) ? "None" : uploadProgress.Exception.ToString());
            else
                _logger.WriteTrace("Upload Aborted... Exited without returning a status!");
        }
    }

输出代码段
[5224](T101)VSLLC:异常!!!类型:Google.GoogleApiException
[5224](T101)VSLLC:GoogleApiException->消息:Google.Apis.Requests.RequestError
[5224]错误请求[400]
[5224]错误[
[5224]消息[错误请求]位置[-]原因[badRequest]域[全局]
[5224]]
[5224](T101)VSLLC:GoogleApiException->状态代码:0
[5224](T101)VSLLC:上传完成。。。状态:失败异常?:服务管理员引发异常:Google.GoogleApiException:Google.Apis.RequestError
[5224]错误请求[400]
[5224]错误[
[5224]消息[错误请求]位置[-]原因[badRequest]域[全局]
[5224]]
[5224]
[5224],位于Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
[5224],位于Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(任务任务)
[5224],位于Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(任务任务)
[5224]在Google.Apis.Upload.RemotableUpload`1.d__0.MoveNext()中,位于c:\code\Google.com\Google api dotnet client\default\Tools\Google.Apis.Release \bin\Debug\output\default\Src\GoogleApis\Media]\Upload\ResumeableUpload.cs:line 373

很抱歉帖子太多了!谢谢你抽出时间!

  1. 该库已经支持503个响应的指数回退。在400(错误请求)的情况下,您不应该重试,因为您会一次又一次地得到相同的响应。查看服务初始值设定项参数DefaultExponentialBackOffPolicy您也可以查看我们的ExponentialBackOff实现。BackOffHandler封装逻辑并实现不成功的响应处理程序和异常处理程序
  2. GoogleApiRequest已不存在
  3. 您可以在这里找到,我们似乎没有正确设置状态代码。我在我们的问题跟踪器中打开了一个新问题,可在此处获取-https://code.google.com/p/google-api-dotnet-client/issues/detail?id=425.请随意添加更多内容

相关内容

  • 没有找到相关文章

最新更新