|
| 1 | +using System; |
| 2 | + |
| 3 | +namespace QueryDB.Exceptions |
| 4 | +{ |
| 5 | + /// <summary> |
| 6 | + /// Represents exceptions specific to QueryDB operations. |
| 7 | + /// </summary> |
| 8 | + public class QueryDBException : Exception |
| 9 | + { |
| 10 | + /// <summary> |
| 11 | + /// Gets the type of the error that occurred. |
| 12 | + /// </summary> |
| 13 | + public string ErrorType { get; } |
| 14 | + |
| 15 | + /// <summary> |
| 16 | + /// Gets additional information about the error, if available. |
| 17 | + /// </summary> |
| 18 | + public string AdditionalInfo { get; } |
| 19 | + |
| 20 | + /// <summary> |
| 21 | + /// Initializes a new instance of the <see cref="QueryDBException"/> class. |
| 22 | + /// </summary> |
| 23 | + /// <param name="message">The error message that describes the error.</param> |
| 24 | + /// <param name="errorType">The type of the error.</param> |
| 25 | + /// <param name="additionalInfo">Optional additional information about the error.</param> |
| 26 | + public QueryDBException(string message, string errorType, string additionalInfo = null) : base(message) |
| 27 | + { |
| 28 | + ErrorType = errorType; |
| 29 | + AdditionalInfo = additionalInfo; |
| 30 | + } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Returns a string representation of the exception, including error type and additional information. |
| 34 | + /// </summary> |
| 35 | + /// <returns>A string containing the error type, message, and additional information.</returns> |
| 36 | + public override string ToString() |
| 37 | + { |
| 38 | + string info = string.IsNullOrEmpty(AdditionalInfo) ? "" : $", Info: {AdditionalInfo}"; |
| 39 | + return $"Type: {ErrorType}, Message: {Message}{info}"; |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// Provides predefined error types, messages, and additional information for QueryDB exceptions. |
| 45 | + /// </summary> |
| 46 | + internal static class QueryDBExceptions |
| 47 | + { |
| 48 | + /// <summary> |
| 49 | + /// Defines standard error types for QueryDB exceptions. |
| 50 | + /// </summary> |
| 51 | + internal static class ErrorType |
| 52 | + { |
| 53 | + /// <summary> |
| 54 | + /// Error type indicating an unsupported command. |
| 55 | + /// </summary> |
| 56 | + internal static string UnsupportedCommand = "UnsupportedCommand"; |
| 57 | + } |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Defines standard error messages for QueryDB exceptions. |
| 61 | + /// </summary> |
| 62 | + internal static class ErrorMessage |
| 63 | + { |
| 64 | + /// <summary> |
| 65 | + /// Error message indicating that SELECT queries are not supported. |
| 66 | + /// </summary> |
| 67 | + internal static string UnsupportedSelectExecuteCommand = "SELECT queries are not supported here."; |
| 68 | + } |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Defines additional information related to QueryDB exceptions. |
| 72 | + /// </summary> |
| 73 | + internal static class AdditionalInfo |
| 74 | + { |
| 75 | + /// <summary> |
| 76 | + /// Additional information about unsupported SELECT queries in 'ExecuteCommand'. |
| 77 | + /// </summary> |
| 78 | + internal static string UnsupportedSelectExecuteCommand = "'ExecuteCommand' doesn't support SELECT queries."; |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments