Skip to content

Deserialization: separate error and body deserializations #3797

@jeremymeng

Description

@jeremymeng

Not blocking, not high pri but should be nice to have.

For example,

export async function _submitBatchDeserialize(result: PathUncheckedResponse): Promise<{
  body: FileContents | { contents: FileContents; contentType?: string; filename?: string };
}> {
  const expectedStatuses = ["202"];
  if (!expectedStatuses.includes(result.status)) {
    const error = createRestError(result);
    error.details = errorXmlDeserializer(result.body);
    error.details = { ...(error.details as any), errorCode: result.headers["x-ms-error-code"] };
    const restErrorCodeValue = result.headers["x-ms-error-code"];
    if (restErrorCodeValue !== undefined) {
      error.code = restErrorCodeValue;
    }
    throw error;
  }

  return _submitBatchRequestDeserializer(result.body) as any;
}

It would be great to have the error-checking part before the last return as a helper function that can be called separately without doing anything to the result.body.

In Storage we had to manually call _submitBatchSend(), _submitBatchDeserializeHeaders(), and checking for error. calling _submitBatchDeserialize() is fine because we can discard the return value. But it's doing unnecessary work. Also for other/future operations, it may not be good to consume the body.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions