-
Notifications
You must be signed in to change notification settings - Fork 5
Support for custom errors #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
f95a3be
89f0c83
f120fd9
46e885f
3058f5e
fb91f08
a7f8f19
ea2082a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,9 @@ | |
| using Microsoft.AspNetCore.Mvc; | ||
| using NorthwindCRUD.Models.DbModels; | ||
| using NorthwindCRUD.Models.Dtos; | ||
| using NorthwindCRUD.Models.Errors; | ||
| using NorthwindCRUD.Services; | ||
| using Swashbuckle.AspNetCore.Annotations; | ||
|
|
||
| [ApiController] | ||
| [Route("[controller]")] | ||
|
|
@@ -76,7 +78,10 @@ public ActionResult<OrderDto[]> GetOrdersByCustomerId(string id) | |
| } | ||
|
|
||
| [HttpPost] | ||
| [Authorize] | ||
| [SwaggerResponse(400, "Your inputs do not pass validation!", typeof(Errors), "text/json")] | ||
|
||
| [SwaggerResponse(401, "Not authenticated!", typeof(CustomError), "text/json")] | ||
dafo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // [Authorize] | ||
| public ActionResult<CustomerDto> Create(CustomerDto model) | ||
| { | ||
| try | ||
|
|
@@ -126,7 +131,10 @@ public ActionResult<CustomerDto> Update(CustomerDto model) | |
| } | ||
|
|
||
| [HttpDelete("{id}")] | ||
| [Authorize] | ||
| [SwaggerResponse(401, "Not authenticated!", typeof(CustomError), "text/json")] | ||
dafo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [SwaggerResponse(404, "Your client is not found!", typeof(CustomError), "text/json")] | ||
dafo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // [Authorize] | ||
| public ActionResult<CustomerDto> Delete(string id) | ||
| { | ||
| try | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| namespace NorthwindCRUD.Models.Errors | ||
| { | ||
| public class CustomError | ||
| { | ||
| public CustomError() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need of empty constructor. |
||
| { | ||
| } | ||
|
|
||
| public int StatusCode { get; set; } | ||
|
|
||
| public string Message { get; set; } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| namespace NorthwindCRUD.Models.Errors | ||
| { | ||
| public class Errors | ||
| { | ||
| public Errors() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need of empty constructor. |
||
| { | ||
| } | ||
|
|
||
| public ValidationError[] CustomErrors { get; set; } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using System.ComponentModel; | ||
|
|
||
| namespace NorthwindCRUD.Models.Errors | ||
| { | ||
| public class ValidationError : CustomError | ||
| { | ||
| public ValidationError() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need of empty constructor. |
||
| { | ||
| } | ||
|
|
||
| public string DataField { get; set; } | ||
| } | ||
| } | ||

Uh oh!
There was an error while loading. Please reload this page.