Skip to content

Commit

Permalink
Update to better support exceptions during uploads.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizoi committed Oct 24, 2023
1 parent 183c936 commit b4c7f94
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
1 change: 0 additions & 1 deletion SmugMugCore.Net/Service/ImageUploaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public ImageUploaderService(Core.SmugMugCore core)
response?.Dispose();
}


throw new ApplicationException("Image upload to smugmug failed for: " + fileInfo.Name);
}

Expand Down
47 changes: 22 additions & 25 deletions SmugMugCoreSync/Repositories/TargetAlbumRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,38 +537,35 @@ private async static Task<ImageUpload> UploadMedia(SmugMugCore core, AlbumDetail
// Attempt #1
return await core.ImageUploaderService.UploadUpdatedImage(targetAlbum.AlbumId, targetImageId, targetMetadata);
}
catch (AggregateException agg)
catch (HttpRequestException httpReqEx)
{
SmugMugException? smugEx = agg.InnerExceptions[0] as SmugMugException;
HttpRequestException? httpReqEx = agg.InnerExceptions[0] as HttpRequestException;

if (smugEx != null)
// Non-SmugMugException - Retry just once (possibly network related)
Trace.WriteLine($" > RETRY (Failed: {targetMetadata?.FileInfo?.Name}) = {httpReqEx.Message}");
System.Threading.Thread.Sleep(1000);
return await core.ImageUploaderService.UploadUpdatedImage(targetAlbum.AlbumId, targetImageId, targetMetadata);
}
catch (SmugMugException smugEx)
{
// Unknown File Type - skip
if (smugEx.ErrorResponse.Code == 64)
{
// Unknown File Type - skip
if (smugEx.ErrorResponse.Code == 64)
{
Trace.WriteLine(" > ERROR 64 (Invalid File Type): " + smugEx.QueryString);
throw new ApplicationException("Invalid File Type");
}
else
{
// Attempt #2 (then blow up and escalate higher)
Trace.WriteLine(" > RETRY ERROR " + smugEx.ErrorResponse.Code + " Query=" + smugEx.QueryString);
System.Threading.Thread.Sleep(1000);
return await core.ImageUploaderService.UploadUpdatedImage(targetAlbum.AlbumId, targetImageId, targetMetadata);
}
Trace.WriteLine(" > ERROR 64 (Invalid File Type): " + smugEx.QueryString);
throw new ApplicationException("Invalid File Type");
}
else if (httpReqEx != null)
else
{
// Non-SmugMugException - Retry just once (possibly network related)
Trace.WriteLine(" > RETRY, HttpRequestException = " + httpReqEx.Message);
// Attempt #2 (then blow up and escalate higher)
Trace.WriteLine(" > RETRY ERROR " + smugEx.ErrorResponse.Code + " Query=" + smugEx.QueryString);
System.Threading.Thread.Sleep(1000);
return await core.ImageUploaderService.UploadUpdatedImage(targetAlbum.AlbumId, targetImageId, targetMetadata);
}
else
{
throw;
}
}
catch (Exception ex)
{
// Attempt #2 (then blow up and escalate higher)
Trace.WriteLine($" > RETRY (Failed: {targetMetadata?.FileInfo?.Name}) = {ex.Message}");
System.Threading.Thread.Sleep(1000);
return await core.ImageUploaderService.UploadUpdatedImage(targetAlbum.AlbumId, targetImageId, targetMetadata);
}
}

Expand Down

0 comments on commit b4c7f94

Please sign in to comment.