Skip to content

Commit 9b5d6cd

Browse files
committed
feat: rethrow error and fix status code
1 parent 11d4af0 commit 9b5d6cd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ApiToolKit.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ public async Task InvokeAsync(HttpContext context)
3737
Guid uuid = Guid.NewGuid();
3838
var msg_id = uuid.ToString();
3939
context.Items["APITOOLKIT_MSG_ID"] = msg_id;
40+
int statusCode = 0;
4041

4142
try
4243
{
44+
4345
await _next(context); // execute the next middleware in the pipeline
4446
}
4547
catch (Exception ex)
4648
{
49+
statusCode = 500;
4750
Client.ReportError(context, ex);
51+
throw;
4852
}
4953
finally
5054
{
@@ -80,7 +84,11 @@ public async Task InvokeAsync(HttpContext context)
8084
{
8185
errors = (List<ATError>)errorListObj;
8286
}
83-
var payload = _client.BuildPayload("DotNet", stopwatch, context.Request, context.Response.StatusCode,
87+
if (statusCode == 0)
88+
{
89+
statusCode = context.Response.StatusCode;
90+
}
91+
var payload = _client.BuildPayload("DotNet", stopwatch, context.Request, statusCode,
8492
System.Text.Encoding.UTF8.GetBytes(requestBody), System.Text.Encoding.UTF8.GetBytes(responseBody),
8593
responseHeaders, pathParams, urlPath, errors, msg_id);
8694

0 commit comments

Comments
 (0)