Merge branch 'develop' of github.com:Frappet/hrms-api-backend into develop
This commit is contained in:
commit
6d3d14445f
8 changed files with 232 additions and 34 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -16,6 +16,9 @@
|
||||||
# Mono auto generated files
|
# Mono auto generated files
|
||||||
mono_crash.*
|
mono_crash.*
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
.vs/
|
||||||
|
|
||||||
# Build results
|
# Build results
|
||||||
[Dd]ebug/
|
[Dd]ebug/
|
||||||
[Dd]ebugPublic/
|
[Dd]ebugPublic/
|
||||||
|
|
|
||||||
6
.idea/.idea.BMA.EHR.Solution/.idea/AndroidProjectSystem.xml
generated
Normal file
6
.idea/.idea.BMA.EHR.Solution/.idea/AndroidProjectSystem.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AndroidProjectSystem">
|
||||||
|
<option name="providerId" value="RiderAndroidProjectSystem" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
11
.idea/.idea.BMA.EHR.Solution/.idea/aws.xml
generated
Normal file
11
.idea/.idea.BMA.EHR.Solution/.idea/aws.xml
generated
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="accountSettings">
|
||||||
|
<option name="activeRegion" value="us-east-1" />
|
||||||
|
<option name="recentlyUsedRegions">
|
||||||
|
<list>
|
||||||
|
<option value="us-east-1" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="RiderProjectSettingsUpdater">
|
<component name="RiderProjectSettingsUpdater">
|
||||||
<option name="singleClickDiffPreview" value="1" />
|
<option name="singleClickDiffPreview" value="1" />
|
||||||
|
<option name="unhandledExceptionsIgnoreList" value="1" />
|
||||||
<option name="vcsConfiguration" value="3" />
|
<option name="vcsConfiguration" value="3" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
File diff suppressed because one or more lines are too long
16
.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml
generated
16
.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml
generated
|
|
@ -39,14 +39,18 @@
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="85fddeb6-44fd-40a4-864f-89daec07db75" name="Changes" comment="" />
|
<list default="true" id="85fddeb6-44fd-40a4-864f-89daec07db75" name="Changes" comment="">
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BMA.EHR.Application/Repositories/PermissionRepository.cs" beforeDir="false" afterPath="$PROJECT_DIR$/BMA.EHR.Application/Repositories/PermissionRepository.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BMA.EHR.Domain/Middlewares/ErrorHandlerMiddleware.cs" beforeDir="false" afterPath="$PROJECT_DIR$/BMA.EHR.Domain/Middlewares/ErrorHandlerMiddleware.cs" afterDir="false" />
|
||||||
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="DpaMonitoringSettings">
|
<component name="DpaMonitoringSettings">
|
||||||
<option name="autoShow" value="false" />
|
<option name="firstShow" value="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
|
|
@ -57,6 +61,7 @@
|
||||||
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/bf9021a960b74107a7e141aa06bc9d8a0a53c929178c2fb95b1597be8af8dc/ExceptionDispatchInfo.cs" root0="FORCE_HIGHLIGHTING" />
|
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/bf9021a960b74107a7e141aa06bc9d8a0a53c929178c2fb95b1597be8af8dc/ExceptionDispatchInfo.cs" root0="FORCE_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs" root0="SKIP_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs" root0="SKIP_HIGHLIGHTING" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="MetaFilesCheckinStateConfiguration" checkMetaFiles="true" />
|
||||||
<component name="ProjectColorInfo">{
|
<component name="ProjectColorInfo">{
|
||||||
"customColor": "",
|
"customColor": "",
|
||||||
"associatedIndex": 2
|
"associatedIndex": 2
|
||||||
|
|
@ -69,10 +74,10 @@
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
".NET Launch Settings Profile.BMA.EHR.Leave: https.executor": "Debug",
|
".NET Launch Settings Profile.BMA.EHR.Leave: https.executor": "Debug",
|
||||||
".NET Launch Settings Profile.BMA.EHR.Placement.Service: http.executor": "Run",
|
".NET Launch Settings Profile.BMA.EHR.Placement.Service: http.executor": "Debug",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"git-widget-placeholder": "develop",
|
"git-widget-placeholder": "working",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
|
|
@ -82,7 +87,7 @@
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}]]></component>
|
||||||
<component name="RunManager" selected=".NET Launch Settings Profile.BMA.EHR.Placement.Service: http">
|
<component name="RunManager" selected=".NET Launch Settings Profile.BMA.EHR.Leave: https">
|
||||||
<configuration name="BMA.EHR.CheckInConsumer" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
|
<configuration name="BMA.EHR.CheckInConsumer" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
|
||||||
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.CheckInConsumer/BMA.EHR.CheckInConsumer.csproj" />
|
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.CheckInConsumer/BMA.EHR.CheckInConsumer.csproj" />
|
||||||
<option name="LAUNCH_PROFILE_TFM" value="net8.0" />
|
<option name="LAUNCH_PROFILE_TFM" value="net8.0" />
|
||||||
|
|
@ -566,6 +571,7 @@
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
<option name="version" value="3" />
|
<option name="version" value="3" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="UnityCheckinConfiguration" checkUnsavedScenes="true" />
|
||||||
<component name="UnityProjectConfiguration" hasMinimizedUI="false" />
|
<component name="UnityProjectConfiguration" hasMinimizedUI="false" />
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,8 @@ namespace BMA.EHR.Application.Repositories
|
||||||
|
|
||||||
using (var client = new HttpClient())
|
using (var client = new HttpClient())
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
|
client.DefaultRequestHeaders.Authorization =
|
||||||
|
new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
|
||||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||||
var req = await client.GetAsync(apiPath);
|
var req = await client.GetAsync(apiPath);
|
||||||
var res = await req.Content.ReadAsStringAsync();
|
var res = await req.Content.ReadAsStringAsync();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
using BMA.EHR.Domain.Shared;
|
using BMA.EHR.Domain.Shared;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace BMA.EHR.Domain.Middlewares
|
namespace BMA.EHR.Domain.Middlewares
|
||||||
{
|
{
|
||||||
|
|
@ -23,6 +24,7 @@ namespace BMA.EHR.Domain.Middlewares
|
||||||
var response = context.Response;
|
var response = context.Response;
|
||||||
var statusCode = response.StatusCode;
|
var statusCode = response.StatusCode;
|
||||||
|
|
||||||
|
// ตรวจสอบว่า response ยังไม่ถูกส่งและเป็น status code ที่ต้องการจัดการ
|
||||||
if (!response.HasStarted &&
|
if (!response.HasStarted &&
|
||||||
(statusCode == (int)HttpStatusCode.Unauthorized || statusCode == (int)HttpStatusCode.Forbidden))
|
(statusCode == (int)HttpStatusCode.Unauthorized || statusCode == (int)HttpStatusCode.Forbidden))
|
||||||
{
|
{
|
||||||
|
|
@ -35,43 +37,144 @@ namespace BMA.EHR.Domain.Middlewares
|
||||||
};
|
};
|
||||||
|
|
||||||
response.ContentType = "application/json";
|
response.ContentType = "application/json";
|
||||||
await response.WriteAsJsonAsync(responseModel);
|
|
||||||
|
// ใช้ JsonSerializer แทน WriteAsJsonAsync เพื่อความปลอดภัย
|
||||||
|
var jsonResponse = JsonSerializer.Serialize(responseModel);
|
||||||
|
await response.WriteAsync(jsonResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception error)
|
catch (Exception error)
|
||||||
{
|
{
|
||||||
var response = context.Response;
|
await HandleExceptionAsync(context, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!response.HasStarted)
|
private static async Task HandleExceptionAsync(HttpContext context, Exception error)
|
||||||
|
{
|
||||||
|
var response = context.Response;
|
||||||
|
|
||||||
|
// ตรวจสอบว่า response ยังไม่ถูกส่งไป
|
||||||
|
if (response.HasStarted)
|
||||||
|
{
|
||||||
|
// ถ้า response เริ่มแล้ว ไม่สามารถแก้ไขได้ แค่ log
|
||||||
|
Console.WriteLine("Cannot write error response, stream already started.");
|
||||||
|
Console.WriteLine($"Error: {error}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Clear response เฉพาะเมื่อยังไม่ได้เริ่มส่ง
|
||||||
|
response.Clear();
|
||||||
|
response.ContentType = "application/json";
|
||||||
|
response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
||||||
|
|
||||||
|
// สร้าง error message
|
||||||
|
var msg = error.Message;
|
||||||
|
var inner = error.InnerException;
|
||||||
|
while (inner != null)
|
||||||
{
|
{
|
||||||
response.Clear();
|
msg += $" {inner.Message}\r\n";
|
||||||
response.ContentType = "application/json";
|
inner = inner.InnerException;
|
||||||
response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
|
||||||
|
|
||||||
var msg = error.Message;
|
|
||||||
var inner = error.InnerException;
|
|
||||||
while (inner != null)
|
|
||||||
{
|
|
||||||
msg += $" {inner.Message}\r\n";
|
|
||||||
inner = inner.InnerException;
|
|
||||||
}
|
|
||||||
|
|
||||||
var responseModel = new ResponseObject
|
|
||||||
{
|
|
||||||
Status = response.StatusCode,
|
|
||||||
Message = GlobalMessages.ExceptionOccured,
|
|
||||||
Result = msg
|
|
||||||
};
|
|
||||||
|
|
||||||
await response.WriteAsJsonAsync(responseModel);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
var responseModel = new ResponseObject
|
||||||
{
|
{
|
||||||
// logging กรณีที่ response เริ่มถูกส่งแล้ว
|
Status = response.StatusCode,
|
||||||
Console.WriteLine("Cannot write error response, stream already started.");
|
Message = GlobalMessages.ExceptionOccured,
|
||||||
Console.WriteLine(error);
|
Result = msg
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// ใช้ JsonSerializer และ WriteAsync เพื่อหลีกเลี่ยงปัญหา stream
|
||||||
|
var jsonResponse = JsonSerializer.Serialize(responseModel);
|
||||||
|
await response.WriteAsync(jsonResponse);
|
||||||
|
}
|
||||||
|
catch (Exception writeError)
|
||||||
|
{
|
||||||
|
// ถ้าเขียน response ไม่ได้ ให้ log error
|
||||||
|
Console.WriteLine("Failed to write error response:");
|
||||||
|
Console.WriteLine($"Original Error: {error}");
|
||||||
|
Console.WriteLine($"Write Error: {writeError}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// using BMA.EHR.Domain.Common;
|
||||||
|
// using BMA.EHR.Domain.Shared;
|
||||||
|
// using Microsoft.AspNetCore.Http;
|
||||||
|
// using System.Net;
|
||||||
|
//
|
||||||
|
// namespace BMA.EHR.Domain.Middlewares
|
||||||
|
// {
|
||||||
|
// public class ErrorHandlerMiddleware
|
||||||
|
// {
|
||||||
|
// private readonly RequestDelegate _next;
|
||||||
|
//
|
||||||
|
// public ErrorHandlerMiddleware(RequestDelegate next)
|
||||||
|
// {
|
||||||
|
// _next = next;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public async Task Invoke(HttpContext context)
|
||||||
|
// {
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// await _next(context);
|
||||||
|
//
|
||||||
|
// var response = context.Response;
|
||||||
|
// var statusCode = response.StatusCode;
|
||||||
|
//
|
||||||
|
// if (!response.HasStarted &&
|
||||||
|
// (statusCode == (int)HttpStatusCode.Unauthorized || statusCode == (int)HttpStatusCode.Forbidden))
|
||||||
|
// {
|
||||||
|
// var responseModel = new ResponseObject
|
||||||
|
// {
|
||||||
|
// Status = statusCode,
|
||||||
|
// Message = statusCode == (int)HttpStatusCode.Unauthorized
|
||||||
|
// ? GlobalMessages.NotAuthorized
|
||||||
|
// : GlobalMessages.ForbiddenAccess
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// response.ContentType = "application/json";
|
||||||
|
// await response.WriteAsJsonAsync(responseModel);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// catch (Exception error)
|
||||||
|
// {
|
||||||
|
// var response = context.Response;
|
||||||
|
//
|
||||||
|
// if (!response.HasStarted)
|
||||||
|
// {
|
||||||
|
// response.Clear();
|
||||||
|
// response.ContentType = "application/json";
|
||||||
|
// response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
||||||
|
//
|
||||||
|
// var msg = error.Message;
|
||||||
|
// var inner = error.InnerException;
|
||||||
|
// while (inner != null)
|
||||||
|
// {
|
||||||
|
// msg += $" {inner.Message}\r\n";
|
||||||
|
// inner = inner.InnerException;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// var responseModel = new ResponseObject
|
||||||
|
// {
|
||||||
|
// Status = response.StatusCode,
|
||||||
|
// Message = GlobalMessages.ExceptionOccured,
|
||||||
|
// Result = msg
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// await response.WriteAsJsonAsync(responseModel);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// // logging กรณีที่ response เริ่มถูกส่งแล้ว
|
||||||
|
// Console.WriteLine("Cannot write error response, stream already started.");
|
||||||
|
// Console.WriteLine(error);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue