Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.

Commit b04f5b9

Browse files
committed
Implementata exception status code 504 - close #2
1 parent ba68a6a commit b04f5b9

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace CustomLibrary.ProblemDetails.Exception;
2+
3+
public class GatewayTimeoutException : System.Exception
4+
{
5+
public GatewayTimeoutException()
6+
{
7+
}
8+
9+
public GatewayTimeoutException(string message) : base(message)
10+
{
11+
}
12+
13+
public GatewayTimeoutException(string message, System.Exception innerException) : base(message, innerException)
14+
{
15+
}
16+
}

src/CustomLibrary.ProblemDetails/ResponseException.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,4 +393,32 @@ public static ObjectResult ServiceUnavailable(HttpContext httpContext, System.Ex
393393

394394
return result;
395395
}
396+
397+
public static ObjectResult GatewayTimeout(HttpContext httpContext, System.Exception exc, List<string> validationError = null)
398+
{
399+
var statusCode = StatusCodes.Status504GatewayTimeout;
400+
var problemDetails = new CustomProblemDetails
401+
{
402+
Status = statusCode,
403+
Detail = exc.Message,
404+
Type = $"https://httpstatuses.com/{statusCode}",
405+
Instance = httpContext.Request.Path,
406+
Title = "GatewayTimeout"
407+
};
408+
409+
problemDetails.Extensions.Add("traceId", Activity.Current?.Id ?? httpContext.TraceIdentifier);
410+
//problemDetails.Extensions.Add("errors", exc.Message);
411+
412+
if (validationError?.Any() ?? false)
413+
{
414+
problemDetails.Extensions.Add("errors", validationError);
415+
}
416+
417+
var result = new ObjectResult(problemDetails)
418+
{
419+
StatusCode = statusCode
420+
};
421+
422+
return result;
423+
}
396424
}

0 commit comments

Comments
 (0)