Похожие чаты

Foundation controler protected async Task<IActionResult> ExecuteActionAsync<T>(Func<Task<(int statusCode, T result, string

message)>> action, string methodName)
{
var stopwatch = Stopwatch.StartNew();
var request = _httpContextAccessor.HttpContext.Request;
var user = _httpContextAccessor.HttpContext.User.Identity.IsAuthenticated
? _httpContextAccessor.HttpContext.User.Identity.Name
: "Anonymous";

try
{
var (statusCode, result, message) = await action();
return AcResponse(statusCode, message, result);
}
catch (Exception ex)
{
_logger.LogError(ex, "An error occurred in {MethodName}. User: {User}. URL: {Url}. Query: {Query}",
methodName, user, request.Path, request.QueryString);
return AcResponse(500, "An error occurred while processing your request.", default(T), new List<string> { ex.Message });
}
finally
{
stopwatch.Stop();
_logger.LogInformation("{MethodName} executed in {Duration} ms. User: {User}. URL: {Url}. Query: {Query}",
methodName, stopwatch.ElapsedMilliseconds, user, request.Path, request.QueryString);
}
}

protected IActionResult AcResponse<T>(int status, string message, T data, List<string> errors = null)
{
var response = new APIResponse<T>(status, message, data, errors);
return StatusCode(status, response);
}
Application:
[HttpPost]
public async Task<IActionResult> Post([FromBody] AddEmailRequest model)
{
return await ExecuteActionAsync(async () =>
{

await Task.Delay(100);

var data = new { Id = 1, model.Email, Setting = _config.CurrentValue.Setting1 };

var ss = 0;
return (201, data, "Data posted successfully");

}, MethodBase.GetCurrentMethod().Name);
}

this or custom filter would be better for the cause?, in filter also i have to send the method name via reflecton anyways

just tying out things


aim: no try catch, + method name , user loged in , time taken all in every action

6 ответов

45 просмотров

Flat controller 🤮

Jass- Автор вопроса
D
Flat controller 🤮

everything in all controllers?

Стикер

Jass- Автор вопроса

thats for only exceptions, my main moto is get all the metrics

Jass
thats for only exceptions, my main moto is get all...

you can create a base class that has 1. status code 2. is success or not. 3. T Data for generic result 4. message for description of result

Jass- Автор вопроса
Mr Thieves
you can create a base class that has 1. status cod...

i do that for every response but i want metrics, will try reflection in middleware i have that ready too

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта