PlanTempusApp/PlanTempus.Core/CommandQueries/ProblemDetails.cs
Janus C. H. Knudsen 7fc1ae0650 WIP
2026-01-10 20:39:17 +01:00

56 lines
No EOL
2.3 KiB
C#

namespace PlanTempus.Core.CommandQueries;
/// <summary>
/// Represents a standardized error response according to RFC 9457 (Problem Details for HTTP APIs).
/// This class provides a consistent way to communicate errors in HTTP APIs, including details about the error type,
/// status code, and additional context. It also supports extensions for custom error information.
///
/// RFC 9457 Documentation: https://www.rfc-editor.org/rfc/rfc9457.html
/// </summary>
public class ProblemDetails
{
/// <summary>
/// A URI reference that identifies the problem type. This is typically a link to human-readable documentation about the error.
/// </summary>
public string Type { get; set; }
/// <summary>
/// A short, human-readable summary of the problem. It should not change between occurrences of the same error.
/// </summary>
public string Title { get; set; }
/// <summary>
/// The HTTP status code generated by the server for this occurrence of the problem. This allows the client to understand the general category of the error.
/// </summary>
public int? Status { get; set; }
/// <summary>
/// A human-readable explanation specific to this occurrence of the problem. It provides additional details about the error.
/// </summary>
public string Detail { get; set; }
/// <summary>
/// A URI reference that identifies the specific occurrence of the problem. This can be used to trace the error in logs or debugging tools.
/// </summary>
public string Instance { get; set; }
/// <summary>
/// A dictionary for additional, custom error information. This allows extending the problem details with application-specific fields.
/// </summary>
[Newtonsoft.Json.JsonExtensionData]
public Dictionary<string, object> Extensions { get; } = new();
/// <summary>
/// Adds a custom extension to the problem details.
/// </summary>
/// <param name="key">The key for the extension.</param>
/// <param name="value">The value of the extension.</param>
public void AddExtension(string key, object value) => Extensions.Add(key, value);
/// <summary>
/// Removes a custom extension from the problem details.
/// </summary>
/// <param name="key">The key of the extension to remove.</param>
public void RemoveExtension(string key) => Extensions.Remove(key);
}