[core-http] de-serialize before checking internalError#12150
Conversation
Currently we check `parsedBody.error` or `parsedBody` for `code` and
`message` to use in the `RestError` to be thrown. However, we do this
on the raw object from parsing XML.
In the example added to the test, without this fix, the `parsedBody`
from xml parsing is
```js
{ Code: "ContainerAlreadyExists", Message: "The specified container already exists." }
```
but we are accessing the properties with lowercase `code` and `message`.
We should check on the object after de-serializing when we have error
object properly mapped already.
the original XML response.
| // If error response has a body, try to extract error code & message from it | ||
| // Then try to deserialize it using default body mapper | ||
| // If error response has a body, try to deserialize it using default body mapper. | ||
| // Then try to extract error code & message from it |
|
Well done. One remaining issue here is the Looks like we are missing the mapping for export const StorageError: coreHttp.CompositeMapper = {
serializedName: "StorageError",
type: {
name: "Composite",
className: "StorageError",
modelProperties: {
message: {
xmlName: "Message",
serializedName: "Message",
type: {
name: "String"
}
}
}
}
};
export const DataLakeStorageErrorError: coreHttp.CompositeMapper = {
serializedName: "DataLakeStorageError_error",
type: {
name: "Composite",
className: "DataLakeStorageErrorError",
modelProperties: {
code: {
xmlName: "Code",
serializedName: "Code",
type: {
name: "String"
}
},
message: {
xmlName: "Message",
serializedName: "Message",
type: {
name: "String"
}
}
}
}
};Need to fix this for all four packages. And I wonder what the |
@ljian3377 yes, Storage side needs a swagger transformation to add the Code property. Also note that this changes the Storage error message even though it's a bug fix. We might want to bump minor version of Storage packages. |
joheredi
left a comment
There was a problem hiding this comment.
Looks good! Would you mind porting this fix to @azure/core-client?
Done porting. Was waiting for feedback first before porting. |
@jeremymeng FYI, we are going to release the GA version of the previous beta in the November release, which bumped up the minor version. |
|
When will this be merged? |
xirzec
left a comment
There was a problem hiding this comment.
The deserialization logic is very complex, so I'm not sure if my comments all make sense. 😅
| @@ -247,14 +243,26 @@ function handleErrorResponse( | |||
| } | |||
| } | |||
| if (error.response) { | |||
There was a problem hiding this comment.
while reading this code, I'm not sure why this if is here, since error.response === parsedResponse and since we're already inside if (parsedResponse.parsedBody) presumably parsedResponse must be true.
There was a problem hiding this comment.
This if check was added in last change by @sarangan12? I will remove
There was a problem hiding this comment.
Checking on error.response removed.
| if (defaultBodyMapper) { | ||
| if (error.response) { |
There was a problem hiding this comment.
can't we combine these?
if (defaultBodyMapper && error.response) {There was a problem hiding this comment.
Checking on error.response removed.
| deserializedError = operationSpec.serializer.deserialize( | ||
| defaultBodyMapper, | ||
| valueToDeserialize, | ||
| "error.response.parsedBody" |
There was a problem hiding this comment.
This is trying to deserialize valueToDeserialize.error.response.parsedBody ? Is there a reason we don't pass that property in as the valueToDeserialize instead?
There was a problem hiding this comment.
I was trying to keep the current code/logic. It deserializes and assigns to error.response.parsedBody I was a little surprised that the code
const errorResponse: FullOperationResponse = error.response;
errorResponse.parsedBody = operationSpec.serializer.deserialize(also updates error.response.parsedBody
There was a problem hiding this comment.
There is some extra handling of sequence type I think that's why valueToDeserialize is introduced.
There was a problem hiding this comment.
This const is also introduced in last PR. @sarangan12 do you remember the reason why this change?
There was a problem hiding this comment.
I guess it's to cast error.response back to FullOperationResponse so we can assign the parsedBody property. I updated this PR to remove the if check on error.response, and do as FulloperationResponse cast.
There was a problem hiding this comment.
I feel like this could be cleaned up more, but I am too scared to suggest any specific changes this close to release, so I think I'm good with it.
- Cast `error.response` back to `FullOperationResponse` so we could assign it's `parsedBody` property
python track2 configure (Azure#12150)
Currently we check
parsedBody.errororparsedBodyforcodeandmessageto use in theRestErrorto be thrown. However, we do thison the raw object from parsing XML.
In the example added to the test, without this fix, the
parsedBodyfrom xml parsing is
but we are accessing the properties with lowercase
codeandmessage.We should check on the object after de-serializing when we have error
object properly mapped already.