Add domain exception handling for authorization and data conflicts
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
#if NETFRAMEWORK
|
||||||
|
using System;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.Domain.Exceptions
|
||||||
|
{
|
||||||
|
public class AuthorizationException : Exception
|
||||||
|
{
|
||||||
|
public AuthorizationException(string message) : base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorizationException()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,5 +9,9 @@ namespace EnvelopeGenerator.Domain.Exceptions
|
|||||||
public DataIntegrityException(string message) : base(message)
|
public DataIntegrityException(string message) : base(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DataIntegrityException() : base()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
namespace EnvelopeGenerator.Server.Middleware;
|
namespace EnvelopeGenerator.Server.Middleware;
|
||||||
|
|
||||||
using DigitalData.Core.Exceptions;
|
using DigitalData.Core.Exceptions;
|
||||||
|
using EnvelopeGenerator.Domain.Exceptions;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@@ -74,6 +75,16 @@ public class ExceptionHandlingMiddleware
|
|||||||
message = forbiddenEx.Message;
|
message = forbiddenEx.Message;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case AuthorizationException authorizationEx:
|
||||||
|
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||||
|
message = authorizationEx.Message;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DataIntegrityException dataIntegrityEx:
|
||||||
|
context.Response.StatusCode = (int)HttpStatusCode.Conflict;
|
||||||
|
message = dataIntegrityEx.Message;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
logger.LogError(exception, "Unhandled exception occurred.");
|
logger.LogError(exception, "Unhandled exception occurred.");
|
||||||
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
||||||
|
|||||||
Reference in New Issue
Block a user