| | 1 | | using System.Text.Json.Serialization; |
| | 2 | |
|
| | 3 | | namespace planora.Domain.Errors; |
| | 4 | |
|
| | 5 | | public record AppError |
| | 6 | | { |
| 24 | 7 | | private AppError(string code, string description, ErrorType type) |
| | 8 | | { |
| 24 | 9 | | Code = code; |
| 24 | 10 | | Description = description; |
| 24 | 11 | | Type = type; |
| 24 | 12 | | } |
| | 13 | |
|
| 0 | 14 | | public string Code { get; } |
| 0 | 15 | | public string Description { get; } |
| | 16 | |
|
| | 17 | | [JsonIgnore] |
| 0 | 18 | | public ErrorType Type { get; } |
| | 19 | |
|
| | 20 | | public static AppError Unexpected(string code, string description) |
| | 21 | | { |
| 8 | 22 | | return new AppError(code, description, ErrorType.Unexpected); |
| | 23 | | } |
| | 24 | |
|
| | 25 | | public static AppError Validation(string code, string description) |
| | 26 | | { |
| 4 | 27 | | return new AppError(code, description, ErrorType.Validation); |
| | 28 | | } |
| | 29 | |
|
| | 30 | | public static AppError Conflict(string code, string description) |
| | 31 | | { |
| 0 | 32 | | return new AppError(code, description, ErrorType.Conflict); |
| | 33 | | } |
| | 34 | |
|
| | 35 | | public static AppError NotFound(string code, string description) |
| | 36 | | { |
| 12 | 37 | | return new AppError(code, description, ErrorType.NotFound); |
| | 38 | | } |
| | 39 | | } |