-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
ErrorResponse.cs
70 lines (65 loc) · 1.97 KB
/
ErrorResponse.cs
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
namespace Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.Models
{
using Newtonsoft.Json;
public partial class ErrorResponse
{
private string code;
private string message;
/// <summary>
/// Error code.
/// </summary>
public string Code
{
get
{
if (code == null)
{
code = GetCodeFromAdditionalProperties();
}
return code;
}
}
/// <summary>
/// A description of the error.
/// </summary>
public string Message
{
get
{
if (message == null)
{
message = GetMessageFromAdditionalProperties();
}
return message;
}
}
private string GetCodeFromAdditionalProperties()
{
if (AdditionalProperties == null) return "Generic error";
if (AdditionalProperties.TryGetValue("error", out object data))
{
var error = JsonConvert.DeserializeObject<OperationError>(data.ToString());
return error.Code;
}
if (AdditionalProperties.TryGetValue("statusCode", out data))
{
return data.ToString();
}
return "Generic error";
}
private string GetMessageFromAdditionalProperties()
{
if (AdditionalProperties == null) return "Generic error";
if (AdditionalProperties.TryGetValue("error", out object data))
{
var error = JsonConvert.DeserializeObject<OperationError>(data.ToString());
return error.Message;
}
if (AdditionalProperties.TryGetValue("message", out data))
{
return data.ToString();
}
return "Generic message";
}
}
}