From 3b1e46d4d64e8c814b4624ac6babf305bf585f02 Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Sun, 30 Apr 2017 08:26:08 -0400 Subject: [PATCH] Implemented CatalogImageMissingException in LocalFileImageService --- .../Exceptions/CatalogImageMissingException.cs | 9 +++++++-- .../FileSystem/LocalFileImageService.cs | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/ApplicationCore/Exceptions/CatalogImageMissingException.cs b/src/ApplicationCore/Exceptions/CatalogImageMissingException.cs index a7c1062..ff07258 100644 --- a/src/ApplicationCore/Exceptions/CatalogImageMissingException.cs +++ b/src/ApplicationCore/Exceptions/CatalogImageMissingException.cs @@ -4,10 +4,15 @@ namespace ApplicationCore.Exceptions { public class CatalogImageMissingException : Exception { - public CatalogImageMissingException(string message, - Exception innerException = null) + public CatalogImageMissingException(string message, + Exception innerException = null) : base(message, innerException: innerException) { } + public CatalogImageMissingException(Exception innerException) + : base("No catalog image found for the provided id.", + innerException: innerException) + { + } } } diff --git a/src/Infrastructure/FileSystem/LocalFileImageService.cs b/src/Infrastructure/FileSystem/LocalFileImageService.cs index ab876af..82db8b2 100644 --- a/src/Infrastructure/FileSystem/LocalFileImageService.cs +++ b/src/Infrastructure/FileSystem/LocalFileImageService.cs @@ -1,4 +1,5 @@ -using ApplicationCore.Interfaces; +using ApplicationCore.Exceptions; +using ApplicationCore.Interfaces; using Microsoft.AspNetCore.Hosting; using System.IO; @@ -14,9 +15,16 @@ namespace Infrastructure.FileSystem } public byte[] GetImageBytesById(int id) { - var contentRoot = _env.ContentRootPath + "//Pics"; - var path = Path.Combine(contentRoot, id + ".png"); - return File.ReadAllBytes(path); + try + { + var contentRoot = _env.ContentRootPath + "//Pics"; + var path = Path.Combine(contentRoot, id + ".png"); + return File.ReadAllBytes(path); + } + catch (FileNotFoundException ex) + { + throw new CatalogImageMissingException(ex); + } } } }