* Fix LRO RestErrors parsing

* Add JSON parsing error handling
This commit is contained in:
Kamil Pajdzik 2019-01-07 12:56:21 -08:00 коммит произвёл GitHub
Родитель cee5adbef6
Коммит 56432e04b9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -397,7 +397,15 @@ class LocationLROPollStrategy extends LROPollStrategy {
lroPollState.resource = getResponseBody(result); lroPollState.resource = getResponseBody(result);
} else if (400 <= statusCode && statusCode <= 499) { } else if (400 <= statusCode && statusCode <= 499) {
const resultBody: string = result.bodyAsText!; const resultBody: string = result.bodyAsText!;
throw new RestError(resultBody, undefined, statusCode, stripRequest(result.request), result, resultBody); let errorMessage: string = resultBody;
try {
const resultObject = JSON.parse(resultBody);
errorMessage = resultObject.message;
} catch (parseError) {
// Ignore the exception, use resultBody as the error message
}
throw new RestError(errorMessage, undefined, statusCode, stripRequest(result.request), result, resultBody);
} else { } else {
throw new Error(`The response with status code ${statusCode} from polling for long running operation url "${lroPollState.locationHeaderValue}" is not valid.`); throw new Error(`The response with status code ${statusCode} from polling for long running operation url "${lroPollState.locationHeaderValue}" is not valid.`);
} }

Просмотреть файл

@ -5,7 +5,7 @@
"email": "azsdkteam@microsoft.com", "email": "azsdkteam@microsoft.com",
"url": "https://github.com/Azure/ms-rest-azure-js" "url": "https://github.com/Azure/ms-rest-azure-js"
}, },
"version": "1.3.0", "version": "1.3.1",
"description": "Isomorphic Azure client runtime for Typescript/node.js/browser javascript client libraries generated using AutoRest", "description": "Isomorphic Azure client runtime for Typescript/node.js/browser javascript client libraries generated using AutoRest",
"tags": [ "tags": [
"isomorphic", "isomorphic",