diff --git a/lib/lroPollStrategy.ts b/lib/lroPollStrategy.ts index a545855..78a50d1 100644 --- a/lib/lroPollStrategy.ts +++ b/lib/lroPollStrategy.ts @@ -397,7 +397,15 @@ class LocationLROPollStrategy extends LROPollStrategy { lroPollState.resource = getResponseBody(result); } else if (400 <= statusCode && statusCode <= 499) { 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 { throw new Error(`The response with status code ${statusCode} from polling for long running operation url "${lroPollState.locationHeaderValue}" is not valid.`); } diff --git a/package.json b/package.json index 8f1209a..d863af6 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "email": "azsdkteam@microsoft.com", "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", "tags": [ "isomorphic",