Implemented CatalogImageMissingException in LocalFileImageService

This commit is contained in:
Steve Smith
2017-04-30 08:26:08 -04:00
parent bc088beb83
commit 3b1e46d4d6
2 changed files with 19 additions and 6 deletions

View File

@@ -4,10 +4,15 @@ namespace ApplicationCore.Exceptions
{ {
public class CatalogImageMissingException : Exception public class CatalogImageMissingException : Exception
{ {
public CatalogImageMissingException(string message, public CatalogImageMissingException(string message,
Exception innerException = null) Exception innerException = null)
: base(message, innerException: innerException) : base(message, innerException: innerException)
{ {
} }
public CatalogImageMissingException(Exception innerException)
: base("No catalog image found for the provided id.",
innerException: innerException)
{
}
} }
} }

View File

@@ -1,4 +1,5 @@
using ApplicationCore.Interfaces; using ApplicationCore.Exceptions;
using ApplicationCore.Interfaces;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using System.IO; using System.IO;
@@ -14,9 +15,16 @@ namespace Infrastructure.FileSystem
} }
public byte[] GetImageBytesById(int id) public byte[] GetImageBytesById(int id)
{ {
var contentRoot = _env.ContentRootPath + "//Pics"; try
var path = Path.Combine(contentRoot, id + ".png"); {
return File.ReadAllBytes(path); var contentRoot = _env.ContentRootPath + "//Pics";
var path = Path.Combine(contentRoot, id + ".png");
return File.ReadAllBytes(path);
}
catch (FileNotFoundException ex)
{
throw new CatalogImageMissingException(ex);
}
} }
} }
} }