From 8df392ef48ef9f4ba3fe9b10621270955824b3df Mon Sep 17 00:00:00 2001 From: katlyn Date: Thu, 19 Jan 2023 10:05:21 -0700 Subject: [PATCH] Added a catch statement to ignore forbidden images --- .../Utilities/Translators/CcbPerson.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Slingshot.CCB/Slingshot.CCB/Utilities/Translators/CcbPerson.cs b/Slingshot.CCB/Slingshot.CCB/Utilities/Translators/CcbPerson.cs index abd1b01..0ec3593 100644 --- a/Slingshot.CCB/Slingshot.CCB/Utilities/Translators/CcbPerson.cs +++ b/Slingshot.CCB/Slingshot.CCB/Utilities/Translators/CcbPerson.cs @@ -228,13 +228,22 @@ public static Person Translate( XElement inputPerson ) // CCB encoded key expires too quickly, so download immediately instead of setting person.PersonPhotoUrl Task.Run( () => { - // save image locally - var imageResponse = WebRequest.Create( imageURI ).GetResponse(); - var imageStream = imageResponse.GetResponseStream(); - var path = Path.Combine( ImportPackage.ImageDirectory, "Person_" + person.Id + ".jpg" ); - using ( FileStream output = File.OpenWrite( path ) ) + // Intentionally skip any damaged or troublesome images here: + try { - imageStream.CopyTo( output ); + // save image locally + var imageResponse = WebRequest.Create( imageURI ).GetResponse(); + var imageStream = imageResponse.GetResponseStream(); + var path = Path.Combine( ImportPackage.ImageDirectory, "Person_" + person.Id + ".jpg" ); + using ( FileStream output = File.OpenWrite( path ) ) + { + imageStream.CopyTo( output ); + } + } + catch ( Exception ) + { + // Continue and ignored forbidden files + } } ); }