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

Commit c83c3fc

Browse files
committed
Implementata exception status code 502 - close #4
1 parent d174cc5 commit c83c3fc

File tree

2 files changed

+43
-0
lines changed

2 files changed

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

src/CustomLibrary.ProblemDetails/ResponseException.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,32 @@ public static ObjectResult NotImplemented(HttpContext httpContext, System.Except
337337

338338
return result;
339339
}
340+
341+
public static ObjectResult BadGateway(HttpContext httpContext, System.Exception exc, List<string> validationError = null)
342+
{
343+
var statusCode = StatusCodes.Status502BadGateway;
344+
var problemDetails = new CustomProblemDetails
345+
{
346+
Status = statusCode,
347+
Detail = exc.Message,
348+
Type = $"https://httpstatuses.com/{statusCode}",
349+
Instance = httpContext.Request.Path,
350+
Title = "BadGateway"
351+
};
352+
353+
problemDetails.Extensions.Add("traceId", Activity.Current?.Id ?? httpContext.TraceIdentifier);
354+
//problemDetails.Extensions.Add("errors", exc.Message);
355+
356+
if (validationError?.Any() ?? false)
357+
{
358+
problemDetails.Extensions.Add("errors", validationError);
359+
}
360+
361+
var result = new ObjectResult(problemDetails)
362+
{
363+
StatusCode = statusCode
364+
};
365+
366+
return result;
367+
}
340368
}

0 commit comments

Comments
 (0)