public static class Thrower
{
public static Exception ThrowIfFailedValidation<T>(T target, Func<T, bool> validation)
{
if (validation(target) is false)
{
throw new ValidationFailedException();
}
}
public static Exception ThrowIfNullOrWhitespace(string? text, string? message)
{
if (string.IsNullOrWhiteSpace(text))
{
throw new TextNullOrWhitespaceException(message);
}
}
public static Exception ThrowForbidden(string message, int resultCode)
{
throw new ForbiddenException(HttpStatusCode.Forbidden, message, resultCode);
}
public static Exception ThrowBadRequest(string message, int resultCode)
{
throw new BadRequestException(HttpStatusCode.BadRequest, message, resultCode);
}
public static Exception Throw500Error(string message, int resultCode)
{
throw new InternalServerErrorException(HttpStatusCode.BadRequest, message, resultCode);
}
...
}