-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProblem.cs
More file actions
102 lines (91 loc) · 3.83 KB
/
Problem.cs
File metadata and controls
102 lines (91 loc) · 3.83 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace ManagedCode.Communication;
/// <summary>
/// A machine-readable format for specifying errors in HTTP API responses based on
/// <see href="https://tools.ietf.org/html/rfc7807" />.
/// </summary>
[JsonConverter(typeof(ProblemJsonConverter))]
public partial class Problem
{
public Problem()
{
Extensions = new Dictionary<string, object?>(StringComparer.Ordinal);
}
/// <summary>
/// A URI reference [RFC3986] that identifies the problem type. This specification encourages that, when
/// dereferenced, it provides human-readable documentation for the problem type
/// (e.g., using HTML [W3C.REC-html5-20141028]). When this member is not present, its value is assumed to be
/// "about:blank".
/// </summary>
[JsonPropertyOrder(-5)]
[JsonPropertyName("type")]
public string Type { get; set; } = "about:blank";
/// <summary>
/// A short, human-readable summary of the problem type. It SHOULD NOT change from occurrence to occurrence
/// of the problem, except for purposes of localization(e.g., using proactive content negotiation;
/// see[RFC7231], Section 3.4).
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyOrder(-4)]
[JsonPropertyName("title")]
public string? Title { get; set; }
/// <summary>
/// The HTTP status code([RFC7231], Section 6) generated by the origin server for this occurrence of the problem.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyOrder(-3)]
[JsonPropertyName("status")]
public int StatusCode { get; set; }
/// <summary>
/// A human-readable explanation specific to this occurrence of the problem.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyOrder(-2)]
[JsonPropertyName("detail")]
public string? Detail { get; set; }
/// <summary>
/// A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information
/// if dereferenced.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyOrder(-1)]
[JsonPropertyName("instance")]
public string? Instance { get; set; }
/// <summary>
/// Gets the <see cref="IDictionary{TKey,TValue}" /> for extension members.
/// <para>
/// Problem type definitions MAY extend the problem details object with additional members. Extension members
/// appear in the same namespace as
/// other members of a problem type.
/// </para>
/// </summary>
/// <remarks>
/// The round-tripping behavior for <see cref="Extensions" /> is determined by the implementation of the Input \ Output
/// formatters.
/// In particular, complex types or collection types may not round-trip to the original type when using the built-in
/// JSON or XML formatters.
/// </remarks>
[JsonExtensionData]
public IDictionary<string, object?> Extensions { get; set; } = new Dictionary<string, object?>(StringComparer.Ordinal);
// Alternative constructor that ensures Extensions is properly initialized
internal Problem(IDictionary<string, object?> extensions) : this()
{
if (extensions != null)
{
foreach (var kvp in extensions)
{
Extensions[kvp.Key] = kvp.Value;
}
}
}
/// <summary>
/// Implicit conversion from Problem to ProblemException.
/// </summary>
public static implicit operator ProblemException(Problem problem)
{
return new ProblemException(problem);
}
}