Skip to content

Commit

Permalink
Fix LRO RestErrors parsing (#104)
Browse files Browse the repository at this point in the history
* Fix LRO RestErrors parsing

* Add JSON parsing error handling
  • Loading branch information
kpajdzik authored Jan 7, 2019
1 parent cee5adb commit 56432e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/lroPollStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"email": "[email protected]",
"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",
Expand Down

0 comments on commit 56432e0

Please sign in to comment.