Skip to content

Commit

Permalink
Merge pull request #575 from radixdlt/return-408-on-timeout
Browse files Browse the repository at this point in the history
return 408 status code on request timeout.
  • Loading branch information
PawelPawelec-RDX authored Nov 30, 2023
2 parents f10db7a + c74105d commit 704a288
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Release Date: _unreleased_

- Fixed exception thrown on empty validator set in the `/state/validator/list` endpoint.
- `524` status code returned instead of `500` if request takes longer than configured timeout.


## 1.2.2
Release Date: 22.11.2023
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private KnownGatewayErrorException HandleException(HttpContext httpContext, Exce
if (requestTimeoutFeature?.CancellationToken.IsCancellationRequested == true)
{
_logger.LogError(exception, "Request timed out after={Timeout} seconds, [RequestTrace={TraceId}]", requestTimeoutFeature.Timeout.TotalSeconds, traceId);
return InternalServerException.OfRequestTimeoutException(exception, traceId);
return new RequestTimeoutException(traceId, $"Request timed out after={requestTimeoutFeature.Timeout.TotalSeconds} seconds");
}

if (requestAbortedFeature?.CancellationToken.IsCancellationRequested == true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,6 @@ public static InternalServerException OfShareableException(Exception exception,
);
}

public static InternalServerException OfRequestTimeoutException(Exception exception, string traceId)
{
var message = $"Request timed out. If reporting this issue, please include TraceId={traceId}";

return new InternalServerException(
new GatewayModel.InternalServerError(exception.GetType().Name, exception.Message),
message,
exception.Message
);
}

public static InternalServerException OfHiddenException(Exception exception, string traceId)
{
var message = $"An unexpected error occurred handling the request. If reporting this issue, please include TraceId={traceId}";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace RadixDlt.NetworkGateway.GatewayApi.Exceptions;

public sealed class RequestTimeoutException : KnownGatewayErrorException
{
/// <summary>
/// Non standard status code (there's no suitable one for such situation).
/// In cloudflare means that the server received complete request but it took to long to process on server side.
/// Wanted to filter these cases out from standard internal server errors.
/// </summary>
private const int RequestTimeoutHttpStatusCode = 524;

public RequestTimeoutException(string traceId, string internalMessage)
: base(RequestTimeoutHttpStatusCode, null, $"Request timed out. If reporting this issue, please include TraceId={traceId}", internalMessage)
{
}
}

0 comments on commit 704a288

Please sign in to comment.