| 1 | namespace HBank.Sdk; |
| 2 | |
| 3 | /// <summary> |
| 4 | /// The API answered with an error. <see cref="Code"/> is the machine-readable error ("invalid_amount", |
| 5 | /// "transaction_not_found", …), <see cref="Status"/> the HTTP status (null when HBank couldn't be reached). |
| 6 | /// </summary> |
| 7 | public class HBankException : Exception |
| 8 | { |
| 9 | public HBankException(string code, int? status, string? detail = null, Exception? inner = null) |
| 10 | : base(detail is null ? code : $"{code}: {detail}", inner) |
| 11 | { |
| 12 | Code = code; |
| 13 | Status = status; |
| 14 | Detail = detail; |
| 15 | } |
| 16 | |
| 17 | public string Code { get; } |
| 18 | public int? Status { get; } |
| 19 | /// <summary>The readable message some errors carry.</summary> |
| 20 | public string? Detail { get; } |
| 21 | } |
| 22 | |
| 23 | /// <summary>401 <c>missing_api_key</c> or 403 <c>invalid_api_key</c>.</summary> |
| 24 | public sealed class HBankAuthenticationException : HBankException |
| 25 | { |
| 26 | public HBankAuthenticationException(string code, int status, string? detail) : base(code, status, detail) { } |
| 27 | } |
| 28 | |
| 29 | /// <summary> |
| 30 | /// HBank couldn't be reached or didn't answer in time (<c>connection_failed</c> / <c>timeout</c>). The request may or |
| 31 | /// may not have reached HBank: before retrying a refund, check <c>Refunded</c> with GetPaymentAsync. |
| 32 | /// </summary> |
| 33 | public sealed class HBankConnectionException : HBankException |
| 34 | { |
| 35 | public HBankConnectionException(string code, string detail, Exception inner) : base(code, null, detail, inner) { } |
| 36 | } |