Azure / Azure/azure-sdk-for-java

[BUG] response errors missing a "message", causing IllegalStateException

Open
#47,681 3 comments 0 reactions 1 assignee Claimed by @alzimmermsft View on GitHub
bug customer-reported needs-team-attention
Dominant language
Java
Stars
2.6k
Forks
2.2k
Avg merge
2d 8h
Merged PRs (30d)
178

Description

**Describe the bug**
When `SearchClient.indexDocuments()` is called and the service returns with status 503 and a JSON error containing an `errorMessage` but not a `message` property, the parsing class SearchError fails with an IllegalStateException because it expects a `message`.

***Exception or Stack Trace***
```
{"trace": "com.azure.core.exception.HttpResponseException: Status code 503, "{"value":[{"key":"x-x-x-x-x","status":false,"errorMessage":"The search service is too busy to process this document. Please try again later.","statusCode":503}]}"
at com.azure.core.implementation.http.rest.RestProxyBase.instantiateUnexpectedException(RestProxyBase.java:330)
at com.azure.core.implementation.http.rest.SyncRestProxy.ensureExpectedStatus(SyncRestProxy.java:125)
at com.azure.core.implementation.http.rest.SyncRestProxy.handleRestReturnType(SyncRestProxy.java:202)
at com.azure.core.implementation.http.rest.SyncRestProxy.invoke(SyncRestProxy.java:82)
at com.azure.core.implementation.http.rest.RestProxyBase.invoke(RestProxyBase.java:110)
at com.azure.core.http.rest.RestProxy.invoke(RestProxy.java:91)
at jdk.proxy3/jdk.proxy3.$Proxy150.indexSync(Unknown Source)
at com.azure.search.documents.implementation.DocumentsImpl.indexWithResponse(DocumentsImpl.java:1077)
at com.azure.search.documents.implementation.util.Utility.lambda$indexDocumentsWithResponse$2(Utility.java:165)
at com.azure.search.documents.implementation.util.Utility.executeRestCallWithExceptionHandling(Utility.java:192)
at com.azure.search.documents.implementation.util.Utility.indexDocumentsWithResponse(Utility.java:163)
at com.azure.search.documents.SearchClient.indexDocumentsWithResponse(SearchClient.java:554)
at com.azure.search.documents.SearchClient.indexDocuments(SearchClient.java:502)
...
Caused by: java.lang.IllegalStateException: Missing required property/properties: message
at com.azure.search.documents.implementation.models.SearchError.lambda$fromJson$1(SearchError.java:122)
at com.azure.json.JsonReader.readMapOrObject(JsonReader.java:551)
at com.azure.json.JsonReader.readObject(JsonReader.java:455)
at com.azure.search.documents.implementation.models.SearchError.fromJson(SearchError.java:88)
at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733)
at com.azure.core.implementation.MethodHandleReflectiveInvoker.invokeStatic(MethodHandleReflectiveInvoker.java:22)
at com.azure.core.implementation.ReflectionSerializable.deserializeAsJsonSerializable(ReflectionSerializable.java:192)
```

**Expected behavior**
The client should throw a `com.azure.core.exception.HttpResponseException` instead.

**Setup (please complete the following information):**
- Library/Libraries: com.azure:azure-core:1.45.1; com.azure:azure-search-documents:11.6.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.