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

Commit 08cd145

Browse files
authored
Merge pull request #26 from AngeloDotNet/12-status-code-management-500
12 status code management 500
2 parents 8f8ea0a + c062dba commit 08cd145

File tree

4 files changed

+152
-78
lines changed

4 files changed

+152
-78
lines changed

README.md

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,31 @@ Collection of tools related to problem management (exceptions) that can be gener
44

55
This library is an ad hoc code customization used in my private/work projects thus avoiding the duplication of repetitive code.
66

7-
## Configuration in ConfigureServices in Startup.cs
8-
9-
```csharp
10-
services.AddProblemDetails();
11-
```
12-
13-
## Configuration in Configure in Startup.cs
14-
15-
```csharp
16-
app.UseProblemDetails();
17-
```
18-
19-
## Example of use
20-
21-
```csharp
22-
[HttpGet("{id}")]
23-
public async Task<IActionResult> GetPerson(Guid id)
24-
{
25-
try
26-
{
27-
var person = await myService.GetItemAsync(id);
28-
29-
if (person == null)
30-
{
31-
throw new CustomLibrary.ProblemDetails.Exception.NotFoundException($"Person with id {id} not found");
32-
}
33-
34-
return Ok(new CustomLibrary.ProblemDetails.Response.Confirm(person));
35-
}
36-
catch (NotFoundException exc)
37-
{
38-
return CustomLibrary.ProblemDetails.Response.NotFound(HttpContext, exc);
39-
}
40-
}
41-
```
42-
43-
# List of Exception Responses
44-
45-
| Status Codes | Exception | Exception Response | |
46-
| --- | --- | --- | --- |
47-
| 304 | Exception.NotModifiedException | Response.NotModified | available |
48-
| 400 | Exception.BadRequestException | Response.BadRequest | available |
49-
| 401 | Exception.UnauthorizedException | Response.Unauthorized | available |
50-
| 403 | Exception.ForbiddenException | Response.Forbidden | available |
51-
| 404 | Exception.NotFoundException | Response.NotFound | available |
52-
| 405 | Exception.NotAllowedException | Response.MethodNotAllowed | available |
53-
| 406 | Exception.NotAcceptableException | Response.NotAcceptable | available |
54-
| 408 | Exception.RequestTimeoutException | Response.RequestTimeout | available |
55-
| 409 | Exception.ConflictException | Response.Conflict | available |
56-
| 422 | Exception.UnprocessableEntityException | Response.UnprocessableEntity | available |
57-
| 500 | Exception.InternalServerErrorException | Response.InternalServerError | coming soon |
58-
| 501 | Exception.NotImplementedException | Response.NotImplemented | coming soon |
59-
| 502 | Exception.BadGatewayException | Response.BadGateway | coming soon |
60-
| 503 | Exception.ServiceUnavailableException | Response.ServiceUnavailable | coming soon |
61-
| 504 | Exception.GatewayTimeoutException | Response.GatewayTimeout | coming soon |
7+
## How to use ?
8+
9+
A full example is available in the CustomLibrary.ProblemDetails.Sample folder or click [here]().
10+
11+
>**Note:** For correct operation it is necessary to add ***services.AddProblemDetails();*** and ***app.UseProblemDetails();*** to the Program class or in the Startup class
12+
13+
## List of Exception Responses
14+
15+
| Status Codes | Exception | Status |
16+
| --- | --- | --- |
17+
| 304 | NotModifiedException | available |
18+
| 400 | BadRequestException | available |
19+
| 401 | UnauthorizedException | available |
20+
| 403 | ForbiddenException | available |
21+
| 404 | NotFoundException | available |
22+
| 405 | NotAllowedException | available |
23+
| 406 | NotAcceptableException | available |
24+
| 408 | RequestTimeoutException | available |
25+
| 409 | ConflictException | available |
26+
| 422 | UnprocessableEntityException | available |
27+
| 500 | InternalServerErrorException | available |
28+
| 501 | NotImplementedException | coming soon |
29+
| 502 | BadGatewayException | coming soon |
30+
| 503 | ServiceUnavailableException | coming soon |
31+
| 504 | GatewayTimeoutException | coming soon |
6232

6333
## Contributing
6434

src/CustomLibrary.ProblemDetails/Response/Confirm.cs renamed to src/CustomLibrary.ProblemDetails/Confirm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace CustomLibrary.ProblemDetails.Response;
1+
namespace CustomLibrary.ProblemDetails;
22

33
public class Confirm
44
{
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 InternalServerErrorException : System.Exception
4+
{
5+
public InternalServerErrorException()
6+
{
7+
}
8+
9+
public InternalServerErrorException(string message) : base(message)
10+
{
11+
}
12+
13+
public InternalServerErrorException(string message, System.Exception innerException) : base(message, innerException)
14+
{
15+
}
16+
}

0 commit comments

Comments
 (0)