Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package com.microsoft.azure;

import com.fasterxml.jackson.databind.node.ObjectNode;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -33,6 +35,11 @@ public final class CloudError {
*/
private List<CloudError> details;

/**
* The inner error.
*/
private ObjectNode innerError;

/**
* Initializes a new instance of CloudError.
*/
Expand Down Expand Up @@ -100,4 +107,11 @@ public CloudError withTarget(String target) {
public List<CloudError> details() {
return details;
}

/**
* @return the inner error
*/
public ObjectNode innerError() {
return innerError;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public CloudError deserialize(JsonParser p, DeserializationContext ctxt) throws
nodeContent = nodeContent.replaceFirst("(?i)\"code\"", "\"code\"")
.replaceFirst("(?i)\"message\"", "\"message\"")
.replaceFirst("(?i)\"target\"", "\"target\"")
.replaceFirst("(?i)\"details\"", "\"details\"");
.replaceFirst("(?i)\"details\"", "\"details\"")
.replaceFirst("(?i)\"innererror\"", "\"innerError\"");
JsonParser parser = new JsonFactory().createParser(nodeContent);
parser.setCodec(mapper);
return parser.readValueAs(CloudError.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.microsoft.azure.serializer.AzureJacksonAdapter;
import com.microsoft.rest.protocol.SerializerAdapter;
import org.junit.Assert;
import org.junit.Test;

public class CloudErrorDeserializerTests {
@Test
public void errorDeserializedFully() throws Exception {
SerializerAdapter<ObjectMapper> serializerAdapter = new AzureJacksonAdapter();
String bodyString =
"{" +
" \"error\": {" +
" \"code\": \"BadArgument\"," +
" \"message\": \"The provided database ‘foo’ has an invalid username.\"," +
" \"target\": \"query\"," +
" \"details\": [" +
" {" +
" \"code\": \"301\"," +
" \"target\": \"$search\"," +
" \"message\": \"$search query option not supported\"" +
" }" +
" ]," +
" \"innererror\": {" +
" \"customKey\": \"customValue\"" +
" }" +
" }" +
"}";
CloudError cloudError = serializerAdapter.deserialize(bodyString, CloudError.class);

Assert.assertEquals("BadArgument", cloudError.code());
Assert.assertEquals("The provided database ‘foo’ has an invalid username.", cloudError.message());
Assert.assertEquals("query", cloudError.target());
Assert.assertEquals("301", cloudError.details().get(0).code());
Assert.assertEquals("customValue", cloudError.innerError().get("customKey").asText());
}
}