Skip to content

Commit c4418cd

Browse files
chore: add tsg link in error messages (Azure#43597)
* chore: add tsg link in error messages * pr feedback * add missing error parser
1 parent 87239dd commit c4418cd

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,8 @@ public virtual async Task<Response<ConfigurationSetting>> AddConfigurationSettin
200200
case 200:
201201
case 201:
202202
return await CreateResponseAsync(response, cancellationToken).ConfigureAwait(false);
203-
case 412:
204-
throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser());
205203
default:
206-
throw new RequestFailedException(response);
204+
throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser());
207205
}
208206
}
209207
catch (Exception e)
@@ -239,10 +237,8 @@ public virtual Response<ConfigurationSetting> AddConfigurationSetting(Configurat
239237
case 200:
240238
case 201:
241239
return CreateResponse(response);
242-
case 412:
243-
throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser());
244240
default:
245-
throw new RequestFailedException(response);
241+
throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser());
246242
}
247243
}
248244
catch (Exception e)
@@ -309,10 +305,9 @@ public virtual async Task<Response<ConfigurationSetting>> SetConfigurationSettin
309305
return response.Status switch
310306
{
311307
200 => await CreateResponseAsync(response, cancellationToken).ConfigureAwait(false),
312-
409 => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()),
313308

314309
// Throws on 412 if resource was modified.
315-
_ => throw new RequestFailedException(response),
310+
_ => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()),
316311
};
317312
}
318313
catch (Exception e)
@@ -352,10 +347,9 @@ public virtual Response<ConfigurationSetting> SetConfigurationSetting(Configurat
352347
return response.Status switch
353348
{
354349
200 => CreateResponse(response),
355-
409 => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()),
356350

357351
// Throws on 412 if resource was modified.
358-
_ => throw new RequestFailedException(response),
352+
_ => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()),
359353
};
360354
}
361355
catch (Exception e)
@@ -441,10 +435,9 @@ private async Task<Response> DeleteConfigurationSettingAsync(string key, string
441435
{
442436
200 => response,
443437
204 => response,
444-
409 => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()),
445438

446439
// Throws on 412 if resource was modified.
447-
_ => throw new RequestFailedException(response)
440+
_ => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()),
448441
};
449442
}
450443
catch (Exception e)
@@ -470,10 +463,9 @@ private Response DeleteConfigurationSetting(string key, string label, MatchCondi
470463
{
471464
200 => response,
472465
204 => response,
473-
409 => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()),
474466

475467
// Throws on 412 if resource was modified.
476-
_ => throw new RequestFailedException(response)
468+
_ => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()),
477469
};
478470
}
479471
catch (Exception e)
@@ -596,7 +588,7 @@ internal virtual async Task<Response<ConfigurationSetting>> GetConfigurationSett
596588
{
597589
200 => await CreateResponseAsync(response, cancellationToken).ConfigureAwait(false),
598590
304 => CreateResourceModifiedResponse(response),
599-
_ => throw new RequestFailedException(response),
591+
_ => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser())
600592
};
601593
}
602594
catch (Exception e)
@@ -633,7 +625,7 @@ internal virtual Response<ConfigurationSetting> GetConfigurationSetting(string k
633625
{
634626
200 => CreateResponse(response),
635627
304 => CreateResourceModifiedResponse(response),
636-
_ => throw new RequestFailedException(response),
628+
_ => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser())
637629
};
638630
}
639631
catch (Exception e)
@@ -1386,7 +1378,7 @@ private async ValueTask<Response<ConfigurationSetting>> SetReadOnlyAsync(string
13861378
200 => async
13871379
? await CreateResponseAsync(response, cancellationToken).ConfigureAwait(false)
13881380
: CreateResponse(response),
1389-
_ => throw new RequestFailedException(response)
1381+
_ => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()),
13901382
};
13911383
}
13921384
catch (Exception e)
@@ -1469,22 +1461,24 @@ private static RequestContext CreateRequestContext(ErrorOptions errorOptions, Ca
14691461

14701462
private class ConfigurationRequestFailedDetailsParser : RequestFailedDetailsParser
14711463
{
1464+
private const string TroubleshootingMessage =
1465+
"For troubleshooting information, see https://aka.ms/azsdk/net/appconfiguration/troubleshoot.";
14721466
public override bool TryParse(Response response, out ResponseError error, out IDictionary<string, string> data)
14731467
{
14741468
switch (response.Status)
14751469
{
14761470
case 409:
1477-
error = new ResponseError(null, "The setting is read only");
1471+
error = new ResponseError(null, $"The setting is read only. {TroubleshootingMessage}");
14781472
data = null;
14791473
return true;
14801474
case 412:
1481-
error = new ResponseError(null, "Setting was already present.");
1475+
error = new ResponseError(null, $"Setting was already present. {TroubleshootingMessage}");
14821476
data = null;
14831477
return true;
14841478
default:
1485-
error = null;
1479+
error = new ResponseError(null, TroubleshootingMessage);
14861480
data = null;
1487-
return false;
1481+
return true;
14881482
}
14891483
}
14901484
}

sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationMockTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class ConfigurationMockTests : ClientTestBase
2929
private static readonly string s_credential = "b1d9b31";
3030
private static readonly string s_secret = "aabbccdd";
3131
private static readonly string s_connectionString = $"Endpoint={s_endpoint};Id={s_credential};Secret={s_secret}";
32+
private static readonly string s_troubleshootingLink = "https://aka.ms/azsdk/net/appconfiguration/troubleshoot";
3233
private static readonly string s_version = new ConfigurationClientOptions().Version;
3334

3435
private static readonly ConfigurationSetting s_testSetting = new ConfigurationSetting("test_key", "test_value")
@@ -108,6 +109,27 @@ public void GetNotFound()
108109
Assert.AreEqual(404, exception.Status);
109110
}
110111

112+
// This test validates that the client throws an exception with the expected error message when it receives a
113+
// non-success status code from the service.
114+
[TestCase((int)HttpStatusCode.Unauthorized)]
115+
[TestCase(403)]
116+
[TestCase((int)HttpStatusCode.NotFound)]
117+
public void GetUnsucessfulResponse(int statusCode)
118+
{
119+
var response = new MockResponse(statusCode);
120+
var mockTransport = new MockTransport(response);
121+
ConfigurationClient service = CreateTestService(mockTransport);
122+
123+
RequestFailedException exception = Assert.ThrowsAsync<RequestFailedException>(async () =>
124+
{
125+
await service.GetConfigurationSettingAsync(key: s_testSetting.Key);
126+
});
127+
128+
Assert.AreEqual(statusCode, exception.Status);
129+
130+
Assert.True(exception?.Message.Contains(s_troubleshootingLink));
131+
}
132+
111133
[Test]
112134
public async Task GetIfChangedModified()
113135
{

0 commit comments

Comments
 (0)