File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
SectigoCertificateManager.Tests
SectigoCertificateManager Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -105,4 +105,16 @@ public async Task ExceptionMessageTruncatesLongBody() {
105
105
Assert . Contains ( new string ( 'a' , 200 ) , ex . Message ) ;
106
106
Assert . DoesNotContain ( new string ( 'a' , 201 ) , ex . Message ) ;
107
107
}
108
+
109
+ [ Fact ]
110
+ public async Task ExceptionMessageIncludesErrorCode ( ) {
111
+ var response = new HttpResponseMessage ( HttpStatusCode . BadRequest ) {
112
+ Content = JsonContent . Create ( new ApiError { Code = ApiErrorCode . ErrorWhileDecodingCsr , Description = "Invalid" } )
113
+ } ;
114
+
115
+ using var client = CreateClient ( response ) ;
116
+
117
+ var ex = await Assert . ThrowsAsync < ValidationException > ( ( ) => client . GetAsync ( "v1/test" ) ) ;
118
+ Assert . Contains ( $ "Code: { ( int ) ApiErrorCode . ErrorWhileDecodingCsr } ", ex . Message ) ;
119
+ }
108
120
}
Original file line number Diff line number Diff line change @@ -5,8 +5,14 @@ namespace SectigoCertificateManager;
5
5
using System . Net . Http ;
6
6
using System . Text . Json ;
7
7
using System . Threading ;
8
- using System . Threading . Tasks ;
9
-
8
+ using System . Threading . Tasks ; if ( ! string . IsNullOrWhiteSpace ( error . Description ) ) {
9
+ message += $ ", Error: { error . Description } ";
10
+ }
11
+ if ( ( int ) error . Code != 0 ) {
12
+ message += $ ", Code: { ( int ) error . Code } ";
13
+ }
14
+
15
+ error . Description = message ;
10
16
/// <summary>
11
17
/// Handles API error responses.
12
18
/// </summary>
You can’t perform that action at this time.
0 commit comments