From 01c55f296dcb59f83aa139614b3d3cd082aea198 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 13 Jul 2023 15:54:29 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=9A=E0=B8=B1?= =?UTF-8?q?=E0=B9=89=E0=B8=81=20Global=20Exception=20Middleware?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BMA.EHR.Domain/Middlewares/ErrorHandlerMiddleware.cs | 4 +++- BMA.EHR.OrganizationEmployee.Service/Program.cs | 3 ++- BMA.EHR.OrganizationEmployee.Service/appsettings.json | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/BMA.EHR.Domain/Middlewares/ErrorHandlerMiddleware.cs b/BMA.EHR.Domain/Middlewares/ErrorHandlerMiddleware.cs index 74b0d660..3bc1c9bf 100644 --- a/BMA.EHR.Domain/Middlewares/ErrorHandlerMiddleware.cs +++ b/BMA.EHR.Domain/Middlewares/ErrorHandlerMiddleware.cs @@ -31,18 +31,20 @@ namespace BMA.EHR.Domain.Middlewares await _next(context); var response = context.Response; - response.ContentType = "application/json"; + var responseModel = new ResponseObject(); responseModel.Status = response.StatusCode; if (responseModel.Status == (int)HttpStatusCode.Unauthorized) { + response.ContentType = "application/json"; responseModel.Message = GlobalMessages.NotAuthorized; await response.WriteAsJsonAsync(responseModel); } if (responseModel.Status == (int)HttpStatusCode.Forbidden) { + response.ContentType = "application/json"; responseModel.Message = GlobalMessages.ForbiddenAccess; await response.WriteAsJsonAsync(responseModel); } diff --git a/BMA.EHR.OrganizationEmployee.Service/Program.cs b/BMA.EHR.OrganizationEmployee.Service/Program.cs index 22d63ad9..3a430cb6 100644 --- a/BMA.EHR.OrganizationEmployee.Service/Program.cs +++ b/BMA.EHR.OrganizationEmployee.Service/Program.cs @@ -113,13 +113,14 @@ var app = builder.Build(); app.UseHttpsRedirection(); + app.UseMiddleware(); app.UseCors(); app.UseAuthentication(); app.UseAuthorization(); app.UseDefaultFiles(); app.UseStaticFiles(); app.MapControllers(); - app.UseMiddleware(); + // apply migrations await using var scope = app.Services.CreateAsyncScope(); diff --git a/BMA.EHR.OrganizationEmployee.Service/appsettings.json b/BMA.EHR.OrganizationEmployee.Service/appsettings.json index 81d5df2d..af28d59b 100644 --- a/BMA.EHR.OrganizationEmployee.Service/appsettings.json +++ b/BMA.EHR.OrganizationEmployee.Service/appsettings.json @@ -14,7 +14,7 @@ "AllowedHosts": "*", "ConnectionStrings": { //"DefaultConnection": "User Id=sys;Password=P@ssw0rd;DBA Privilege=SYSDBA;Data Source=localhost:1521/ORCLCDB", - "DefaultConnection": "server=127.0.0.1;user=root;password=P@ssw0rd;port=3308;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;" + "DefaultConnection": "server=192.168.1.9;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;" }, "Jwt": { "Key": "HP-FnQMUj9msHMSD3T9HtdEnphAKoCJLEl85CIqROFI",