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

Commit eb5fc1a

Browse files
committed
Implementata exception status code 501 - close #5
1 parent 3d895a5 commit eb5fc1a

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 NotImplementedException : System.Exception
4+
{
5+
public NotImplementedException()
6+
{
7+
}
8+
9+
public NotImplementedException(string message) : base(message)
10+
{
11+
}
12+
13+
public NotImplementedException(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
@@ -309,4 +309,32 @@ public static ObjectResult InternalServerError(HttpContext httpContext, System.E
309309

310310
return result;
311311
}
312+
313+
public static ObjectResult NotImplemented(HttpContext httpContext, System.Exception exc, List<string> validationError = null)
314+
{
315+
var statusCode = StatusCodes.Status501NotImplemented;
316+
var problemDetails = new CustomProblemDetails
317+
{
318+
Status = statusCode,
319+
Detail = exc.Message,
320+
Type = $"https://httpstatuses.com/{statusCode}",
321+
Instance = httpContext.Request.Path,
322+
Title = "InternalServerError"
323+
};
324+
325+
problemDetails.Extensions.Add("traceId", Activity.Current?.Id ?? httpContext.TraceIdentifier);
326+
//problemDetails.Extensions.Add("errors", exc.Message);
327+
328+
if (validationError?.Any() ?? false)
329+
{
330+
problemDetails.Extensions.Add("errors", validationError);
331+
}
332+
333+
var result = new ObjectResult(problemDetails)
334+
{
335+
StatusCode = statusCode
336+
};
337+
338+
return result;
339+
}
312340
}

0 commit comments

Comments
 (0)