I'm creating a rest API, using ASP.net Core and bit-framework
We want to allow the clients to be able to delete just the resources that they have created themselves
In case a client asks to delete a resource which is created by another client,
what is the best exception to raise in the API?
What is the most correct HTTP status code to return?
All the exception implemented in Bit.Owin.Exceptions
namespace are:\
BadRequestException
ResourceNotFoundException
AppException
DomainLogicException
should I stick to this list of exceptions in my API? Is this list of exceptions going to be including more exceptions to cover more scenarios?
I think one of these status codes must be returned, but which one suites better our condition?:
Based on @cassiomolin's answer, you can create your own exception type based on following docs:
https://docs.bit-framework.com/introduction/web-api#exception-handling
add exception type to bit framework known exceptions
public class CanNotDeleteOtherClientResourceException : Exception, IKnownException, IHttpStatusCodeAwareException
{
public CanNotDeleteOtherClientResourceException(string message)
: base(message)
{
}
public HttpStatusCode StatusCode { get; set; } = HttpStatusCode.Forbidden;
}