Skip to content

Commit

Permalink
ErrorCode added to NotProcessableException
Browse files Browse the repository at this point in the history
  • Loading branch information
marcwittke committed Dec 13, 2017
1 parent 1e0c6ef commit 57a1904
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Backend.Fx/Exceptions/NotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class NotFoundException<TEntity> : NotFoundException
{
public NotFoundException(int id) : base(typeof(TEntity).Name, id)
public NotFoundException(object id) : base(typeof(TEntity).Name, id)
{}
}

Expand Down
12 changes: 12 additions & 0 deletions src/Backend.Fx/Exceptions/UnprocessableException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,24 @@ public UnprocessableException()
public UnprocessableException(string message) : base(message)
{ }

public UnprocessableException(string message, string errorCode) : base(message)
{
ErrorCode = errorCode;
}

public UnprocessableException(string message, Exception innerException) : base(message, innerException)
{ }

public UnprocessableException(string message, string errorCode, Exception innerException) : base(message, innerException)
{
ErrorCode = errorCode;
}

public static UnprocessableExceptionBuilder UseBuilder()
{
return new UnprocessableExceptionBuilder();
}

public string ErrorCode { get; }
}
}
4 changes: 2 additions & 2 deletions src/Backend.Fx/Exceptions/UnprocessableExceptionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void Add(string error)
errors.Add(error);
}

public void AddNotFoundWhenNull<T>(int id, T t)
public void AddNotFoundWhenNull<T>(object id, T t)
{
if (t == null)
{
Expand All @@ -30,7 +30,7 @@ public void Dispose()
{
if (errors.Any())
{
throw new UnprocessableException("The provided arguments cannot be processed: " + string.Join(", ", errors));
throw new UnprocessableException("The provided arguments cannot be processed: " + string.Join(", ", errors), "ValidationFailed");
}
}

Expand Down

0 comments on commit 57a1904

Please sign in to comment.