mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
Getting model by invalid ID throws a more specific exception.
This commit is contained in:
parent
f3534de0c5
commit
54c36e9264
8 changed files with 38 additions and 11 deletions
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||
using System.Linq.Expressions;
|
||||
using Marr.Data;
|
||||
using Marr.Data.QGen;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Datastore.Events;
|
||||
using NzbDrone.Common;
|
||||
|
@ -73,7 +74,14 @@ namespace NzbDrone.Core.Datastore
|
|||
|
||||
public TModel Get(int id)
|
||||
{
|
||||
return DataMapper.Query<TModel>().Single(c => c.Id == id);
|
||||
var model = DataMapper.Query<TModel>().SingleOrDefault(c => c.Id == id);
|
||||
|
||||
if (model == null)
|
||||
{
|
||||
throw new ModelNotFoundException(typeof(TModel), id);
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public IEnumerable<TModel> Get(IEnumerable<int> ids)
|
||||
|
|
14
NzbDrone.Core/Datastore/ModelNotFoundException.cs
Normal file
14
NzbDrone.Core/Datastore/ModelNotFoundException.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using NzbDrone.Common.Exceptions;
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
{
|
||||
public class ModelNotFoundException : NzbDroneException
|
||||
{
|
||||
public ModelNotFoundException(Type modelType, int modelId)
|
||||
: base("{0} with ID {1} does not exist", modelType.Name, modelId)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue