shoc-backend/Api.SeaHavenIndustries/Filters/ConcurrencyExceptionFilter.cs

22 lines
674 B
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.EntityFrameworkCore;
namespace Api.SeaHavenIndustries.Filters
{
public class ConcurrencyExceptionFilter : IExceptionFilter
{
public void OnException(ExceptionContext context)
{
if (context.Exception is not DbUpdateConcurrencyException) return;
context.Result = new ConflictObjectResult(new
{
status = "Conflict",
message = "The record was modified by another user. Refresh and retry.",
code = 409
});
context.ExceptionHandled = true;
}
}
}