Skip to content

Commit

Permalink
Implemented CatalogImageMissingException in LocalFileImageService
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalis committed Apr 30, 2017
1 parent bc088be commit 3b1e46d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
}
}
16 changes: 12 additions & 4 deletions src/Infrastructure/FileSystem/LocalFileImageService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ApplicationCore.Interfaces;
using ApplicationCore.Exceptions;
using ApplicationCore.Interfaces;
using Microsoft.AspNetCore.Hosting;
using System.IO;

Expand All @@ -14,9 +15,16 @@ public LocalFileImageService(IHostingEnvironment env)
}
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);
}
}
}
}

0 comments on commit 3b1e46d

Please sign in to comment.