From 34f31e59d5c979d3bb271555267ec406bf5bc2ec Mon Sep 17 00:00:00 2001 From: Timo Date: Sun, 21 Apr 2019 23:57:29 +0200 Subject: [PATCH] LUIS: Improve thrown Exception of "AddIntentWithHttpMessagesAsync" Now, the method throws an ErrorResponseException instead of a HttpOperationException (equivalent to all LUIS authoring methods). --- .../Language/LUIS/Authoring/Generated/IModel.cs | 2 +- .../Language/LUIS/Authoring/Generated/Model.cs | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/LUIS/Authoring/Generated/IModel.cs b/src/SDKs/CognitiveServices/dataPlane/Language/LUIS/Authoring/Generated/IModel.cs index 4e3abf48133e..a0d9771b8f67 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/LUIS/Authoring/Generated/IModel.cs +++ b/src/SDKs/CognitiveServices/dataPlane/Language/LUIS/Authoring/Generated/IModel.cs @@ -40,7 +40,7 @@ public partial interface IModel /// /// The cancellation token. /// - /// + /// /// Thrown when the operation returned an invalid status code /// /// diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/LUIS/Authoring/Generated/Model.cs b/src/SDKs/CognitiveServices/dataPlane/Language/LUIS/Authoring/Generated/Model.cs index 2ced64aad804..c7a221276ba2 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/LUIS/Authoring/Generated/Model.cs +++ b/src/SDKs/CognitiveServices/dataPlane/Language/LUIS/Authoring/Generated/Model.cs @@ -68,7 +68,7 @@ public Model(LUISAuthoringClient client) /// /// The cancellation token. /// - /// + /// /// Thrown when the operation returned an invalid status code /// /// @@ -166,12 +166,19 @@ public Model(LUISAuthoringClient client) string _responseContent = null; if ((int)_statusCode != 201) { - var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); - if (_httpResponse.Content != null) { + var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject(_responseContent, Client.DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } } - else { - _responseContent = string.Empty; + catch (JsonException) + { + // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);