Skip to content

Commit

Permalink
Remove body field from RestError Object in core-http Library (#5670)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarangan12 authored and ramya-rao-a committed Oct 20, 2019
1 parent af0a2ce commit 7da8d54
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
12 changes: 6 additions & 6 deletions sdk/core/core-arm/lib/lroPollStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ export abstract class LROPollStrategy {
error.request = stripRequest(this._pollState.mostRecentRequest);
error.response = this._pollState.mostRecentResponse;
error.message = `Long running operation failed with status: "${this._pollState.state}".`;
error.body = this._pollState.resource;
if (error.body) {
const innerError: any = error.body.error;
error.response.parsedBody = this._pollState.resource;
if (error.response.parsedBody) {
const innerError: any = error.response.parsedBody.error;
if (innerError) {
if (innerError.message) {
error.message = `Long running operation failed with error: "${innerError.message}".`;
Expand Down Expand Up @@ -407,7 +407,7 @@ class LocationLROPollStrategy extends LROPollStrategy {
// Ignore the exception, use resultBody as the error message
}

throw new RestError(errorMessage, undefined, statusCode, stripRequest(result.request), result, resultBody);
throw new RestError(errorMessage, undefined, statusCode, stripRequest(result.request), result);
} else {
throw new Error(`The response with status code ${statusCode} from polling for long running operation url "${lroPollState.locationHeaderValue}" is not valid.`);
}
Expand Down Expand Up @@ -484,7 +484,7 @@ class AzureAsyncOperationLROPollStrategy extends LROPollStrategy {
error.statusCode = statusCode;
error.request = stripRequest(response.request);
error.response = response;
error.body = parsedResponse;
error.response.parsedBody = parsedResponse;
throw error;
}

Expand Down Expand Up @@ -567,7 +567,7 @@ class GetResourceLROPollStrategy extends LROPollStrategy {
error.statusCode = statusCode;
error.request = stripRequest(result.request);
error.response = result;
error.body = responseBody;
error.response.parsedBody = responseBody;
throw error;
}

Expand Down
9 changes: 3 additions & 6 deletions sdk/core/core-http/lib/policies/deserializationPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,11 @@ export function deserializeResponseBody(
? parsedErrorResponse[defaultResponseBodyMapper.xmlElementName!]
: [];
}
error.body = operationSpec.serializer.deserialize(
error.response!.parsedBody = operationSpec.serializer.deserialize(
defaultResponseBodyMapper,
valueToDeserialize,
"error.body"
"error.response.parsedBody"
);
// Setting the parsedBody on response to enable flattening as per operationSpec
error.response!.parsedBody = error.body;
}
}

Expand Down Expand Up @@ -270,8 +268,7 @@ function parse(
errCode,
operationResponse.status,
operationResponse.request,
operationResponse,
operationResponse.bodyAsText
operationResponse
);
return Promise.reject(e);
};
Expand Down
5 changes: 1 addition & 4 deletions sdk/core/core-http/lib/restError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ export class RestError extends Error {
statusCode?: number;
request?: WebResource;
response?: HttpOperationResponse;
body?: any;
details?: unknown;
constructor(
message: string,
code?: string,
statusCode?: number,
request?: WebResource,
response?: HttpOperationResponse,
body?: any
response?: HttpOperationResponse
) {
super(message);
this.code = code;
this.statusCode = statusCode;
this.request = request;
this.response = response;
this.body = body;

Object.setPrototypeOf(this, RestError.prototype);
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/test/blobclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe("BlobClient", () => {
"AbortCopyFromClient should be failed and throw exception for an completed copy operation."
);
} catch (err) {
assert.ok((err as any).body.Code === "InvalidHeaderValue");
assert.ok((err as any).response.parsedBody.Code === "InvalidHeaderValue");
}
});

Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/test/node/blobclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe("BlobClient Node.js only", () => {
"AbortCopyFromClient should be failed and throw exception for an completed copy operation."
);
} catch (err) {
assert.ok((err as any).body.Code === "InvalidHeaderValue");
assert.ok((err as any).response.parsedBody.Code === "InvalidHeaderValue");
}
});

Expand Down

0 comments on commit 7da8d54

Please sign in to comment.