I have read many articles now about how to handle errors in asp.net, and I think it is a lot of information to take in.
I'm using service layer pattern, and in my service model, I have the following code:
public List<SpotifyAlbumModel> AddSpotifyAlbums(List<SpotifyAlbumModel> albums)
{
try
{
if(albums != null)
{
ctx.SpotifyAlbums.AddRange(albums);
ctx.SaveChanges();
}
return albums;
}
catch(Exception e)
{
throw new Exception();
}
}
If a problem rises, I want to redirect the user to a error page that says something went wrong.
I call my service method from my controller:
public ActionResult AddSpotifyAlbums(List<SpotifyAlbumModel> albums)
{
_profileService.AddSpotifyAlbums(albums);
return Json(new { data = albums });
}
How can I determine in my controller method if something went wrong in the service, and then redirect the user to the error page?
Or should I have a global errorHandler that transfer the user as soon a excetion is caught?