Skip to content

Commit

Permalink
[ODS-6383] Log configuration documentation update (#1068)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaksn authored Jun 3, 2024
1 parent c242f84 commit 6578b71
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
// See the LICENSE and NOTICES files in the project root for more information.

using System.Threading.Tasks;
using EdFi.Ods.Api.Extensions;
using EdFi.Ods.Common.Context;
using EdFi.Ods.Common.Exceptions;
using EdFi.Ods.Common.Extensions;
using EdFi.Ods.Common.Logging;
using log4net;
using Microsoft.AspNetCore.Http;

Expand All @@ -17,13 +21,14 @@ public class TenantIdentificationMiddleware : IMiddleware
{
private readonly ITenantConfigurationMapProvider _tenantConfigurationMapProvider;
private readonly IContextProvider<TenantConfiguration> _tenantConfigurationContextProvider;

private readonly ILogContextAccessor _logContextAccessor;
private readonly ILog _logger = LogManager.GetLogger(typeof(TenantIdentificationMiddleware));

public TenantIdentificationMiddleware(
public TenantIdentificationMiddleware(ILogContextAccessor logContextAccessor,
ITenantConfigurationMapProvider tenantConfigurationMapProvider,
IContextProvider<TenantConfiguration> tenantConfigurationContextProvider)
{
_logContextAccessor = logContextAccessor;
_tenantConfigurationMapProvider = tenantConfigurationMapProvider;
_tenantConfigurationContextProvider = tenantConfigurationContextProvider;
}
Expand All @@ -43,7 +48,23 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
}
else
{
context.Response.StatusCode = StatusCodes.Status404NotFound;
var tenantIdentifierPart = "";

if (tenantIdentifierAsObject is string tenantIdentifierString)
{
tenantIdentifierPart = $"'{tenantIdentifierString}' ";
}

var problemDetails = new NotFoundException(
NotFoundException.DefaultDetail,
$"The selected tenant {tenantIdentifierPart}does not exist. Check the tenant name and try again.");

string correlationId = _logContextAccessor.GetCorrelationId();
problemDetails.CorrelationId = correlationId;

await context.Response.WriteProblemDetailsAsync(problemDetails);

_logger.Error(problemDetails.Message);

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ Task WriteResponseUsingFormat(
{
string correlationId = _logContextAccessor.GetCorrelationId();
string errorMessage = string.Format(_logMessageFormatSpecifiers[(int)logMessageFormatType], headerName);


_logger.Error(errorMessage);

return response.WriteProblemDetailsAsync(
statusCode,
ProfileContentTypeUsageException.TitleText,
Expand All @@ -230,7 +232,9 @@ Task WriteResponseUsingFormat(
Task WriteResponseMessage(HttpResponse response, int statusCode, string errorMessage)
{
string correlationId = _logContextAccessor.GetCorrelationId();


_logger.Error(errorMessage);

return response.WriteProblemDetailsAsync(
statusCode,
ProfileContentTypeUsageException.TitleText,
Expand Down

0 comments on commit 6578b71

Please sign in to comment.