Files
admin/Azaion.Common/BusinessException.cs
T
Oleksandr Bezdieniezhnykh 88c7b288df [AZ-199] [AZ-200] [AZ-201] [AZ-202] Fix API bugs
Made-with: Cursor
2026-04-16 06:55:11 +03:00

53 lines
1.4 KiB
C#

using System.ComponentModel;
using Azaion.Common.Extensions;
namespace Azaion.Common;
public class BusinessException(ExceptionEnum exEnum) : Exception(GetMessage(exEnum))
{
private static readonly Dictionary<ExceptionEnum, string> ExceptionDescriptions;
static BusinessException()
{
ExceptionDescriptions = EnumExtensions.GetDescriptions<ExceptionEnum>();
}
public ExceptionEnum ExceptionEnum { get; set; } = exEnum;
public static string GetMessage(ExceptionEnum exEnum) => ExceptionDescriptions.GetValueOrDefault(exEnum) ?? exEnum.ToString();
}
public enum ExceptionEnum
{
[Description("No such email found.")]
NoEmailFound = 10,
[Description("Email already exists.")]
EmailExists = 20,
[Description("Passwords do not match.")]
WrongPassword = 30,
[Description("Password should be at least 12 characters.")]
PasswordLengthIncorrect = 32,
[Description("Email is empty or invalid.")]
EmailLengthIncorrect = 35,
WrongEmail = 37,
[Description("User account is disabled.")]
UserDisabled = 38,
[Description("Hardware mismatch! You are not authorized to access this resource from this hardware.")]
HardwareIdMismatch = 40,
[Description("Hardware should be not empty.")]
BadHardware = 45,
[Description("Wrong resource file name.")]
WrongResourceName = 50,
[Description("No file provided.")]
NoFileProvided = 60,
}