Skip to content
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

Support for custom errors #29

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions NorthwindCRUD/Controllers/CustomersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]")]
Expand Down Expand Up @@ -76,7 +78,10 @@ public ActionResult<OrderDto[]> GetOrdersByCustomerId(string id)
}

[HttpPost]
[Authorize]
[SwaggerResponse(400, "Invalid input data!", typeof(Errors), "text/json")]
[SwaggerResponse(401, "Unauthorized!", typeof(CustomError), "text/json")]

// [Authorize]
public ActionResult<CustomerDto> Create(CustomerDto model)
{
try
Expand Down Expand Up @@ -126,7 +131,10 @@ public ActionResult<CustomerDto> Update(CustomerDto model)
}

[HttpDelete("{id}")]
[Authorize]
[SwaggerResponse(401, "Unauthorized!", typeof(CustomError), "text/json")]
[SwaggerResponse(404, "Customer not found!", typeof(CustomError), "text/json")]

// [Authorize]
public ActionResult<CustomerDto> Delete(string id)
{
try
Expand Down
13 changes: 13 additions & 0 deletions NorthwindCRUD/Models/Errors/CustomError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace NorthwindCRUD.Models.Errors
{
public class CustomError
{
public CustomError()
Copy link

Choose a reason for hiding this comment

The 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; }
}
}
11 changes: 11 additions & 0 deletions NorthwindCRUD/Models/Errors/Errors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace NorthwindCRUD.Models.Errors
{
public class Errors
{
public Errors()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need of empty constructor.

{
}

public ValidationError[] CustomErrors { get; set; }
}
}
13 changes: 13 additions & 0 deletions NorthwindCRUD/Models/Errors/ValidationError.cs
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()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need of empty constructor.

{
}

public string DataField { get; set; }
}
}
Loading