-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathContentstackErrorException.cs
More file actions
105 lines (93 loc) · 3.18 KB
/
ContentstackErrorException.cs
File metadata and controls
105 lines (93 loc) · 3.18 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
103
104
105
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Contentstack.Management.Core.Exceptions
{
/// <summary>
/// A base exception for Contentstack API.
/// </summary>
public class ContentstackErrorException: Exception
{
#region Private Variables
private string _ErrorMessage = string.Empty;
#endregion
#region Public Variables
/// <summary>
/// This is http response status code of REST request to Contentstack.
/// </summary>
public HttpStatusCode StatusCode { get; set; }
/// <summary>
/// This is http response Header of REST request to Contentstack.
/// </summary>
public HttpResponseHeaders Header { get; set; }
/// <summary>
/// This is http response phrase code of REST request to Contentstack.
/// </summary>
public string ReasonPhrase { get; set; }
/// <summary>
/// This is error message.
/// </summary>
public new string Message { get; set; }
/// <summary>
/// This is error message.
/// </summary>
[JsonProperty("error_message")]
public string ErrorMessage
{
get
{
return this._ErrorMessage;
}
set
{
this._ErrorMessage = value;
this.Message = value;
}
}
/// <summary>
/// This is error code.
/// </summary>
[JsonProperty("error_code")]
public int ErrorCode { get; set; }
/// <summary>
/// Set of errors in detail.
/// </summary>
[JsonProperty("errors")]
public Dictionary<string, object> Errors { get; set; }
/// <summary>
/// Number of retry attempts made before this exception was thrown.
/// </summary>
public int RetryAttempts { get; set; }
/// <summary>
/// The original exception that caused this error, if this is a network error wrapped in an HTTP exception.
/// </summary>
public Exception OriginalError { get; set; }
/// <summary>
/// Indicates whether this error originated from a network failure.
/// </summary>
public bool IsNetworkError { get; set; }
#endregion
public static ContentstackErrorException CreateException(HttpResponseMessage response)
{
var stringResponse = response.Content.ReadAsStringAsync().Result;
ContentstackErrorException exception = null;
if (!string.IsNullOrEmpty(stringResponse))
{
exception = JObject.Parse(stringResponse).ToObject<ContentstackErrorException>();
}
else
{
exception = new ContentstackErrorException();
}
exception.StatusCode = response.StatusCode;
exception.Header = response.Headers;
exception.ReasonPhrase = response.ReasonPhrase;
return exception;
}
public ContentstackErrorException() { }
}
}