Skip to content

Commit 9ca2fd4

Browse files
author
Ian Shimmings
committed
Improved error reporting
1 parent 92795ec commit 9ca2fd4

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

BtmsGateway/Middleware/MessageData.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ public async Task PopulateResponse(HttpResponse response, RoutingResult routingR
112112
try
113113
{
114114
response.StatusCode = (int)routingResult.StatusCode;
115-
response.ContentType = OriginalContentType;
115+
response.ContentType = OriginalContentType;
116116
response.Headers.Date = (routingResult.ResponseDate ?? DateTimeOffset.Now).ToString("R");
117117
response.Headers[CorrelationIdHeaderName] = CorrelationId;
118118
response.Headers[RequestedPathHeaderName] = routingResult.UrlPath;
119-
if (routingResult.ResponseContent != null && response.StatusCode != (int)HttpStatusCode.NoContent)
120-
await response.BodyWriter.WriteAsync(new ReadOnlyMemory<byte>(Encoding.UTF8.GetBytes(routingResult.ResponseContent)));
119+
if (!string.IsNullOrWhiteSpace($"{routingResult.ResponseContent}{routingResult.ErrorMessage}") && response.StatusCode != (int)HttpStatusCode.NoContent)
120+
await response.BodyWriter.WriteAsync(new ReadOnlyMemory<byte>(Encoding.UTF8.GetBytes($"{routingResult.ResponseContent}{routingResult.ErrorMessage}")));
121121
}
122122
catch (Exception ex)
123123
{

BtmsGateway/Services/Routing/MessageRouter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public async Task<RoutingResult> Route(MessageData messageData)
3737
catch (Exception ex)
3838
{
3939
logger.Error(ex, "Error routing");
40-
return routingResult with { StatusCode = HttpStatusCode.ServiceUnavailable };
40+
return routingResult with { StatusCode = HttpStatusCode.ServiceUnavailable, ErrorMessage = ex.Message };
4141
}
4242
}
4343

0 commit comments

Comments
 (0)