@azure/core-client
Advanced tools
Comparing version 1.0.1-alpha.20210319.1 to 1.0.1-alpha.20210326.1
@@ -146,3 +146,4 @@ // Copyright (c) Microsoft Corporation. | ||
const errorResponseSpec = responseSpec !== null && responseSpec !== void 0 ? responseSpec : operationSpec.responses.default; | ||
const initialErrorMessage = ((_a = parsedResponse.request.streamResponseStatusCodes) === null || _a === void 0 ? void 0 : _a.has(parsedResponse.status)) ? `Unexpected status code: ${parsedResponse.status}` | ||
const initialErrorMessage = ((_a = parsedResponse.request.streamResponseStatusCodes) === null || _a === void 0 ? void 0 : _a.has(parsedResponse.status)) | ||
? `Unexpected status code: ${parsedResponse.status}` | ||
: parsedResponse.bodyAsText; | ||
@@ -149,0 +150,0 @@ const error = new RestError(initialErrorMessage, { |
@@ -33,2 +33,24 @@ // Copyright (c) Microsoft Corporation. | ||
/** | ||
* Maps the response as follows: | ||
* - wraps the response body if needed (typically if its type is primitive). | ||
* - returns null if the combination of the headers and the body is empty. | ||
* - otherwise, returns the combination of the headers and the body. | ||
* | ||
* @param responseObject - a representation of the parsed response | ||
* @returns the response that will be returned to the user which can be null and/or wrapped | ||
* | ||
* @internal | ||
*/ | ||
function handleNullableResponseAndWrappableBody(responseObject) { | ||
const combinedHeadersAndBody = Object.assign(Object.assign({}, responseObject.headers), responseObject.body); | ||
if (responseObject.hasNullableType && | ||
Object.getOwnPropertyNames(combinedHeadersAndBody).length === 0) { | ||
return responseObject.shouldWrapBody ? { body: null } : null; | ||
} | ||
else { | ||
return responseObject.shouldWrapBody | ||
? Object.assign(Object.assign({}, responseObject.headers), { body: responseObject.body }) : combinedHeadersAndBody; | ||
} | ||
} | ||
/** | ||
* Take a `FullOperationResponse` and turn it into a flat | ||
@@ -44,3 +66,12 @@ * response object to hand back to the consumer. | ||
const parsedHeaders = fullResponse.parsedHeaders; | ||
/** | ||
* If body is not asked for, we return the response headers only. If the response | ||
* has a body anyway, that body must be ignored. | ||
*/ | ||
if (fullResponse.request.method === "HEAD") { | ||
return parsedHeaders; | ||
} | ||
const bodyMapper = responseSpec && responseSpec.bodyMapper; | ||
const isNullable = Boolean(bodyMapper === null || bodyMapper === void 0 ? void 0 : bodyMapper.nullable); | ||
/** If the body is asked for, we look at the mapper to handle it */ | ||
if (bodyMapper) { | ||
@@ -65,15 +96,25 @@ const typeName = bodyMapper.type.name; | ||
} | ||
return arrayResponse; | ||
return isNullable && | ||
!fullResponse.parsedBody && | ||
!parsedHeaders && | ||
Object.getOwnPropertyNames(modelProperties).length === 0 | ||
? null | ||
: arrayResponse; | ||
} | ||
if (typeName === "Composite" || typeName === "Dictionary") { | ||
return Object.assign(Object.assign({}, parsedHeaders), fullResponse.parsedBody); | ||
return handleNullableResponseAndWrappableBody({ | ||
body: fullResponse.parsedBody, | ||
headers: parsedHeaders, | ||
hasNullableType: isNullable, | ||
shouldWrapBody: false | ||
}); | ||
} | ||
} | ||
if (bodyMapper || | ||
fullResponse.request.method === "HEAD" || | ||
isPrimitiveType(fullResponse.parsedBody)) { | ||
return Object.assign(Object.assign({}, parsedHeaders), { body: fullResponse.parsedBody }); | ||
} | ||
return Object.assign(Object.assign({}, parsedHeaders), fullResponse.parsedBody); | ||
return handleNullableResponseAndWrappableBody({ | ||
body: fullResponse.parsedBody, | ||
headers: parsedHeaders, | ||
hasNullableType: isNullable, | ||
shouldWrapBody: isPrimitiveType(fullResponse.parsedBody) | ||
}); | ||
} | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@azure/core-client", | ||
"version": "1.0.1-alpha.20210319.1", | ||
"version": "1.0.1-alpha.20210326.1", | ||
"description": "Core library for interfacing with AutoRest generated code", | ||
@@ -125,3 +125,3 @@ "sdk-type": "client", | ||
"sinon": "^9.0.2", | ||
"typescript": "4.1.2", | ||
"typescript": "~4.2.0", | ||
"util": "^0.12.1", | ||
@@ -128,0 +128,0 @@ "typedoc": "0.15.2" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
551257
5019