Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove body field from RestError Object in core-http Library #5670

Merged
merged 4 commits into from
Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the error.details here instead?
this._pollState.resource is not really the parsed body of the response here right?

@sadasant, @chradek, @bterlson

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

details seems appropriate to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thoughts this._pollState.resource has already been updated to parsed response body elsewhere, so this is ok for now, but needs deeper investigation. Opened issue #5680

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