I'm able to get error message through my custom exception class, but it seems it always returning 500 status code.
How can I set the status code using my custom exception class?
this is the app flow:
Service:
throw new UCodeException("Already exist", StatusCodes.Status409Conflict);
UCodeException:
public class UCodeException : UException
{
public override int StatusCode { get; }
public UCodeException(string error, int statusCode) : base(error)
{
StatusCode = statusCode;
}
public UCodeException(string[] errors, int statusCode) : base(errors)
{
StatusCode = statusCode;
}
}
UException:
public abstract class UException : Exception
{
public string[] Errors { get; }
public abstract int StatusCode { get; }
protected UException(string error) : base(error)
{
Errors = new []{error};
}
protected UException(string[] errors)
{
Errors = errors;
}
}