Added failed query logging to datalistfetcher

This commit is contained in:
2020-05-14 13:36:10 +00:00
parent f3eb085169
commit 6b673699cc
2 changed files with 84 additions and 69 deletions

View File

@@ -73,7 +73,7 @@ namespace AyaNova.Api.Controllers
try try
{ {
ApiDataListResponse r = await DataListFetcher.GetResponseAsync(listOptions.DataListKey, ct, listOptions, UserId, UserRoles); ApiDataListResponse r = await DataListFetcher.GetResponseAsync(listOptions.DataListKey, ct, listOptions, UserId, UserRoles, log);
return Ok(r); return Ok(r);
} }
catch (System.UnauthorizedAccessException) catch (System.UnauthorizedAccessException)

View File

@@ -3,7 +3,7 @@ using System.Linq;
using AyaNova.Biz; using AyaNova.Biz;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using AyaNova.Api.ControllerHelpers; using AyaNova.Api.ControllerHelpers;
using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging;
using AyaNova.Models; using AyaNova.Models;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@@ -13,7 +13,7 @@ namespace AyaNova.DataList
{ {
internal static class DataListFetcher internal static class DataListFetcher
{ {
internal static async Task<ApiDataListResponse> GetResponseAsync(string DataListKey, AyContext ct, ListOptions listOptions, long UserId, AuthorizationRoles UserRoles) internal static async Task<ApiDataListResponse> GetResponseAsync(string DataListKey, AyContext ct, ListOptions listOptions, long UserId, AuthorizationRoles UserRoles, ILogger log)
{ {
var DataList = DataListFactory.GetAyaDataList(DataListKey); var DataList = DataListFactory.GetAyaDataList(DataListKey);
@@ -83,6 +83,8 @@ namespace AyaNova.DataList
//GET DATA RETURN ROWS //GET DATA RETURN ROWS
command.CommandText = qDataQuery; command.CommandText = qDataQuery;
try
{
using (var dr = await command.ExecuteReaderAsync()) using (var dr = await command.ExecuteReaderAsync())
{ {
while (dr.Read()) while (dr.Read())
@@ -174,6 +176,19 @@ dr.GetOrdinal("customfields");
} }
} }
} }
catch (Npgsql.PostgresException e)
{
//log out the exception and the query
log.LogInformation("DataList query failed unexpectedly. Data Query was:");
log.LogInformation(qDataQuery);
log.LogInformation("Count Query was:");
log.LogInformation(qTotalRecordsQuery);
log.LogInformation(e, "DB Exception");
throw new System.Exception("DataListFetcher - Query failed see log");
}
}
//BUILD THE COLUMNS RETURN PROPERTY JSON FRAGMENT //BUILD THE COLUMNS RETURN PROPERTY JSON FRAGMENT