File size: 950 Bytes
fd72e32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
namespace AiDevProject.Core.Exceptions;

/// <summary>
/// Base application exception.
/// </summary>
public class AppException : Exception
{
    public int StatusCode { get; }
    public bool IsOperational { get; }

    public AppException(string message, int statusCode = 500, bool isOperational = true)
        : base(message)
    {
        StatusCode = statusCode;
        IsOperational = isOperational;
    }
}

/// <summary>
/// Validation error.
/// </summary>
public class ValidationError : AppException
{
    public ValidationError(string message) : base(message, 400) { }
}

/// <summary>
/// Resource not found.
/// </summary>
public class NotFoundError : AppException
{
    public NotFoundError(string resource) : base($"{resource} not found", 404) { }
}

/// <summary>
/// Authentication failed.
/// </summary>
public class AuthenticationError : AppException
{
    public AuthenticationError() : base("Authentication failed", 401) { }
}