Skip to content

Commit

Permalink
feat: rethrow error and fix status code
Browse files Browse the repository at this point in the history
  • Loading branch information
dawkaka committed Jul 1, 2024
1 parent 11d4af0 commit 9b5d6cd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ApiToolKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ public async Task InvokeAsync(HttpContext context)
Guid uuid = Guid.NewGuid();
var msg_id = uuid.ToString();
context.Items["APITOOLKIT_MSG_ID"] = msg_id;
int statusCode = 0;

try
{

await _next(context); // execute the next middleware in the pipeline
}
catch (Exception ex)
{
statusCode = 500;
Client.ReportError(context, ex);
throw;
}
finally
{
Expand Down Expand Up @@ -80,7 +84,11 @@ public async Task InvokeAsync(HttpContext context)
{
errors = (List<ATError>)errorListObj;
}
var payload = _client.BuildPayload("DotNet", stopwatch, context.Request, context.Response.StatusCode,
if (statusCode == 0)
{
statusCode = context.Response.StatusCode;
}
var payload = _client.BuildPayload("DotNet", stopwatch, context.Request, statusCode,
System.Text.Encoding.UTF8.GetBytes(requestBody), System.Text.Encoding.UTF8.GetBytes(responseBody),
responseHeaders, pathParams, urlPath, errors, msg_id);

Expand Down

0 comments on commit 9b5d6cd

Please sign in to comment.