49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CPRNIMS.Infrastructure.Helper
|
|
{
|
|
public class ErrorLogHelper
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
public string BaseUrl => _configuration["CommonEndpoints:ApiDefaultHeaders:BaseUrl"];
|
|
public ErrorLogHelper(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
}
|
|
public async Task<Entities.Common.ErrorMessage> ErrorLogs(Entities.Common.ErrorMessage errorMessage)
|
|
{
|
|
var httpClient = new HttpClient(new HttpClientHandler
|
|
{
|
|
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true
|
|
})
|
|
{
|
|
BaseAddress = new Uri(BaseUrl)
|
|
};
|
|
var jsonContent = JsonSerializer.Serialize(errorMessage);
|
|
|
|
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
|
|
|
|
var response = await httpClient.PostAsync(_configuration["CommonEndpoints:ApiDefaultHeaders:ErrorMessage"], content);
|
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
|
|
return errorMessage;
|
|
}
|
|
else
|
|
{
|
|
// Handle API request failure
|
|
}
|
|
// Handle token retrieval failure
|
|
return null;
|
|
}
|
|
}
|
|
}
|