Browse Source

Implemented CatalogImageMissingException in LocalFileImageService

main
Steve Smith 9 years ago
parent
commit
3b1e46d4d6
  1. 5
      src/ApplicationCore/Exceptions/CatalogImageMissingException.cs
  2. 16
      src/Infrastructure/FileSystem/LocalFileImageService.cs

5
src/ApplicationCore/Exceptions/CatalogImageMissingException.cs

@ -9,5 +9,10 @@ namespace ApplicationCore.Exceptions
: base(message, innerException: innerException)
{
}
public CatalogImageMissingException(Exception innerException)
: base("No catalog image found for the provided id.",
innerException: innerException)
{
}
}
}

16
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);
}
}
}
}

Loading…
Cancel
Save