From 4e48089c1851fd567cba715b06b280771ae10331 Mon Sep 17 00:00:00 2001 From: Aaron Po Date: Mon, 2 Mar 2026 22:55:02 -0500 Subject: [PATCH] Handle SqlException in global exception filter --- src/Core/API/API.Core/GlobalException.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Core/API/API.Core/GlobalException.cs b/src/Core/API/API.Core/GlobalException.cs index 72f7821..6115f64 100644 --- a/src/Core/API/API.Core/GlobalException.cs +++ b/src/Core/API/API.Core/GlobalException.cs @@ -3,6 +3,7 @@ using API.Core.Contracts.Common; using Domain.Exceptions; using FluentValidation; +using Microsoft.Data.SqlClient; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; @@ -71,6 +72,16 @@ public class GlobalExceptionFilter(ILogger logger) context.ExceptionHandled = true; break; + case SqlException ex: + context.Result = new ObjectResult( + new ResponseBody { Message = "A database error occurred." } + ) + { + StatusCode = 503, + }; + context.ExceptionHandled = true; + break; + case Domain.Exceptions.ValidationException ex: context.Result = new ObjectResult( new ResponseBody { Message = ex.Message }