-
Notifications
You must be signed in to change notification settings - Fork 446
/
Copy pathApiResponseStatusException.cs
53 lines (48 loc) · 1.48 KB
/
ApiResponseStatusException.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
using System;
using System.Net;
using System.Net.Http;
namespace WebApiClientCore.Exceptions
{
/// <summary>
/// 表示接口响应状态码异常
/// </summary>
public class ApiResponseStatusException : ApiException, IStatusCodeException
{
/// <summary>
/// 获取响应消息
/// </summary>
public HttpResponseMessage ResponseMessage { get; }
/// <summary>
/// 获取响应状态码
/// </summary>
public HttpStatusCode StatusCode => this.ResponseMessage.StatusCode;
/// <summary>
/// 获取异常提示消息
/// </summary>
public override string Message
{
get
{
var code = (int)this.ResponseMessage.StatusCode;
var reason = this.ResponseMessage.ReasonPhrase;
return Resx.failure_StatusCode.Format(code, reason);
}
}
/// <summary>
/// 接口响应状态码异常
/// </summary>
/// <param name="responseMessage">响应消息</param>
/// <exception cref="ArgumentNullException"></exception>
public ApiResponseStatusException(HttpResponseMessage responseMessage)
{
this.ResponseMessage = responseMessage;
}
/// <summary>
/// 获取响应状态码
/// </summary>
HttpStatusCode? IStatusCodeException.GetStatusCode()
{
return this.StatusCode;
}
}
}