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

Commit

Permalink
Implementata exception status code 408
Browse files Browse the repository at this point in the history
close #15
  • Loading branch information
AngeloDotNet committed Aug 27, 2023
1 parent d371ebb commit 7d51b76
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace CustomLibrary.ProblemDetails.Exception;

public class RequestTimeoutException : System.Exception
{
public RequestTimeoutException()
{
}

public RequestTimeoutException(string message) : base(message)
{
}

public RequestTimeoutException(string message, System.Exception innerException) : base(message, innerException)
{
}
}
22 changes: 22 additions & 0 deletions src/CustomLibrary.ProblemDetails/Response/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,26 @@ public static ObjectResult NotAcceptable(HttpContext httpContext, System.Excepti

return result;
}

public static ObjectResult RequestTimeout(HttpContext httpContext, System.Exception exc)
{
var statusCode = StatusCodes.Status408RequestTimeout;
var problemDetails = new CustomProblemDetails
{
Status = statusCode,
Type = $"https://httpstatuses.com/{statusCode}",
Instance = httpContext.Request.Path,
Title = "RequestTimeout"
};

problemDetails.Extensions.Add("traceId", Activity.Current?.Id ?? httpContext.TraceIdentifier);
problemDetails.Extensions.Add("errors", exc.Message);

var result = new ObjectResult(problemDetails)
{
StatusCode = statusCode
};

return result;
}
}

0 comments on commit 7d51b76

Please sign in to comment.