Skip to content

Commit c84b21f

Browse files
authored
Formrecognizer update to ResponseError usage (Azure#30212)
1 parent 0e8cfb7 commit c84b21f

19 files changed

+49
-513
lines changed

eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,13 +1325,6 @@
13251325
<Bug pattern="SE_BAD_FIELD"/>
13261326
</Match>
13271327

1328-
<!-- DocumentModelOperationException fields re serializable -->
1329-
<Match>
1330-
<Class name="com.azure.ai.formrecognizer.models.DocumentModelOperationException"/>
1331-
<Field name="documentModelOperationError"/>
1332-
<Bug pattern="SE_BAD_FIELD"/>
1333-
</Match>
1334-
13351328
<!-- TextAnalyticsException fields re serializable -->
13361329
<Match>
13371330
<Class name="com.azure.ai.textanalytics.models.TextAnalyticsException"/>

sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Renamed `getValue*` accessor methods on `DocumentField` to `getValueAs*`
2020
- Renamed `DocTypeInfo` model to `DocumentTypeDetails`
2121
- Renamed `docTypes` property on `DocumentModelDetails` model to `documentTypes`
22+
- Removed models `DocumentModelOperationException`, `DocumentModelOperationError` and `DocumentModelOperationInnerError`.
2223

2324
### Bugs Fixed
2425

sdk/formrecognizer/azure-ai-formrecognizer/migration-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,6 @@ For additional samples please take a look at the [Form Recognizer samples][READM
570570
[GuidelinesJavaDesign]: https://azure.github.io/azure-sdk/java_introduction.html#namespaces
571571
[README-Samples]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/README.md
572572
[README]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/formrecognizer/azure-ai-formrecognizer/README.md
573-
<!-- [service_supported_models]: TODO -->
573+
[service_supported_models]: https://aka.ms/azsdk/formrecognizer/models
574574

575575
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fformrecognizer%2Fazure-ai-formrecognizer%2Fmigration-guide.png)

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/DocumentAnalysisAsyncClient.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
import com.azure.ai.formrecognizer.implementation.util.Transforms;
1212
import com.azure.ai.formrecognizer.models.AnalyzeDocumentOptions;
1313
import com.azure.ai.formrecognizer.models.AnalyzeResult;
14-
import com.azure.ai.formrecognizer.models.DocumentModelOperationException;
1514
import com.azure.ai.formrecognizer.models.DocumentOperationResult;
1615
import com.azure.core.annotation.ReturnType;
1716
import com.azure.core.annotation.ServiceClient;
1817
import com.azure.core.annotation.ServiceMethod;
18+
import com.azure.core.exception.HttpResponseException;
1919
import com.azure.core.http.HttpPipeline;
2020
import com.azure.core.http.rest.Response;
2121
import com.azure.core.util.BinaryData;
@@ -105,7 +105,7 @@ public final class DocumentAnalysisAsyncClient {
105105
*
106106
* @return A {@link PollerFlux} that polls the progress of the analyze document operation until it has completed, has failed,
107107
* or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
108-
* @throws DocumentModelOperationException If analyze operation fails and the {@link AnalyzeResultOperation} returns
108+
* @throws HttpResponseException If analyze operation fails and the {@link AnalyzeResultOperation} returns
109109
* with an {@link OperationStatus#FAILED}..
110110
* @throws IllegalArgumentException If {@code documentUrl} or {@code modelId} is null.
111111
*/
@@ -156,7 +156,7 @@ public final class DocumentAnalysisAsyncClient {
156156
* that may be passed when analyzing documents.
157157
* @return A {@link PollerFlux} that polls progress of the analyze document operation until it has completed,
158158
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
159-
* @throws DocumentModelOperationException If analyze operation fails and the {@link AnalyzeResultOperation} returns
159+
* @throws HttpResponseException If analyze operation fails and the {@link AnalyzeResultOperation} returns
160160
* with an {@link OperationStatus#FAILED}.
161161
* @throws IllegalArgumentException If {@code documentUrl} or {@code modelId} is null.
162162
*/
@@ -256,7 +256,7 @@ public final class DocumentAnalysisAsyncClient {
256256
*
257257
* @return A {@link PollerFlux} that polls the progress of the analyze document operation until it has completed,
258258
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
259-
* @throws DocumentModelOperationException If analyze operation fails and the {@link AnalyzeResultOperation} returns
259+
* @throws HttpResponseException If analyze operation fails and the {@link AnalyzeResultOperation} returns
260260
* with an {@link OperationStatus#FAILED}.
261261
* @throws IllegalArgumentException If {@code document} or {@code modelId} is null.
262262
*/
@@ -313,7 +313,7 @@ public final class DocumentAnalysisAsyncClient {
313313
*
314314
* @return A {@link PollerFlux} that polls the progress of the analyze document operation until it has completed,
315315
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
316-
* @throws DocumentModelOperationException If analyze operation fails and the {@link AnalyzeResultOperation} returns
316+
* @throws HttpResponseException If analyze operation fails and the {@link AnalyzeResultOperation} returns
317317
* with an {@link OperationStatus#FAILED}.
318318
* @throws IllegalArgumentException If {@code document} or {@code modelId} is null.
319319
*/
@@ -417,8 +417,8 @@ private Mono<PollResponse<DocumentOperationResult>> processAnalyzeModelResponse(
417417
status = LongRunningOperationStatus.SUCCESSFULLY_COMPLETED;
418418
break;
419419
case FAILED:
420-
throw logger.logExceptionAsError(
421-
Transforms.toDocumentModelOperationException(analyzeResultOperationResponse.getValue().getError()));
420+
throw logger.logExceptionAsError(Transforms
421+
.mapResponseErrorToHttpResponseException(analyzeResultOperationResponse.getValue().getError()));
422422
default:
423423
status = LongRunningOperationStatus.fromString(
424424
analyzeResultOperationResponse.getValue().getStatus().toString(), true);

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/DocumentAnalysisClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import com.azure.ai.formrecognizer.implementation.models.OperationStatus;
88
import com.azure.ai.formrecognizer.models.AnalyzeDocumentOptions;
99
import com.azure.ai.formrecognizer.models.AnalyzeResult;
10-
import com.azure.ai.formrecognizer.models.DocumentModelOperationException;
1110
import com.azure.ai.formrecognizer.models.DocumentOperationResult;
1211
import com.azure.core.annotation.ReturnType;
1312
import com.azure.core.annotation.ServiceClient;
1413
import com.azure.core.annotation.ServiceMethod;
14+
import com.azure.core.exception.HttpResponseException;
1515
import com.azure.core.util.BinaryData;
1616
import com.azure.core.util.Context;
1717
import com.azure.core.util.polling.SyncPoller;
@@ -79,7 +79,7 @@ public final class DocumentAnalysisClient {
7979
*
8080
* @return A {@link SyncPoller} to poll the progress of the analyze document operation until it has completed,
8181
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
82-
* @throws DocumentModelOperationException If analyze operation fails and the {@link AnalyzeResultOperation} returns
82+
* @throws HttpResponseException If analyze operation fails and the {@link AnalyzeResultOperation} returns
8383
* with an {@link OperationStatus#FAILED}..
8484
* @throws IllegalArgumentException If {@code documentUrl} or {@code modelId} is null.
8585
*/
@@ -123,7 +123,7 @@ public final class DocumentAnalysisClient {
123123
*
124124
* @return A {@link SyncPoller} to poll the progress of the analyze document operation until it has completed,
125125
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
126-
* @throws DocumentModelOperationException If analyze operation fails and the {@link AnalyzeResultOperation} returns
126+
* @throws HttpResponseException If analyze operation fails and the {@link AnalyzeResultOperation} returns
127127
* with an {@link OperationStatus#FAILED}.
128128
* @throws IllegalArgumentException If {@code documentUrl} or {@code modelId} is null.
129129
*/
@@ -168,7 +168,7 @@ public final class DocumentAnalysisClient {
168168
*
169169
* @return A {@link SyncPoller} that polls the of progress of analyze document operation until it has completed,
170170
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
171-
* @throws DocumentModelOperationException If analyze operation fails and the {@link AnalyzeResultOperation}returns
171+
* @throws HttpResponseException If analyze operation fails and the {@link AnalyzeResultOperation}returns
172172
* with an {@link OperationStatus#FAILED}.
173173
* @throws IllegalArgumentException If {@code document} or {@code modelId} is null.
174174
*/
@@ -215,7 +215,7 @@ public final class DocumentAnalysisClient {
215215
*
216216
* @return A {@link SyncPoller} that polls the of progress of analyze document operation until it has completed,
217217
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
218-
* @throws DocumentModelOperationException If analyze operation fails and the {@link AnalyzeResultOperation} returns
218+
* @throws HttpResponseException If analyze operation fails and the {@link AnalyzeResultOperation} returns
219219
* with an {@link OperationStatus#FAILED}.
220220
* @throws IllegalArgumentException If {@code document} or {@code modelId} is null.
221221
*/

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/administration/DocumentModelAdministrationAsyncClient.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.azure.ai.formrecognizer.implementation.util.Transforms;
2828
import com.azure.ai.formrecognizer.implementation.util.Utility;
2929
import com.azure.ai.formrecognizer.models.DocumentAnalysisAudience;
30-
import com.azure.ai.formrecognizer.models.DocumentModelOperationException;
3130
import com.azure.ai.formrecognizer.models.DocumentOperationResult;
3231
import com.azure.core.annotation.ReturnType;
3332
import com.azure.core.annotation.ServiceClient;
@@ -180,7 +179,7 @@ DocumentAnalysisAudience getAudience() {
180179
* for more information on building mode for custom documents.
181180
* @return A {@link PollerFlux} that polls the building model operation until it has completed, has failed, or has
182181
* been cancelled. The completed operation returns the trained {@link DocumentModelDetails custom document analysis model}.
183-
* @throws DocumentModelOperationException If building a model fails with {@link OperationStatus#FAILED} is created.
182+
* @throws HttpResponseException If building a model fails with {@link OperationStatus#FAILED} is created.
184183
* @throws NullPointerException If {@code trainingFilesUrl} is null.
185184
*/
186185
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
@@ -242,7 +241,7 @@ public PollerFlux<DocumentOperationResult, DocumentModelDetails> beginBuildModel
242241
* building a custom document analysis model.
243242
* @return A {@link PollerFlux} that polls the building model operation until it has completed, has failed, or has
244243
* been cancelled. The completed operation returns the trained {@link DocumentModelDetails custom document analysis model}.
245-
* @throws DocumentModelOperationException If building a model fails with {@link OperationStatus#FAILED} is created.
244+
* @throws HttpResponseException If building a model fails with {@link OperationStatus#FAILED} is created.
246245
* @throws NullPointerException If {@code trainingFilesUrl} is null.
247246
*/
248247
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
@@ -499,7 +498,7 @@ Mono<Response<CopyAuthorization>> getCopyAuthorizationWithResponse(
499498
* @param componentModelIds The list of component models to compose.
500499
* @return A {@link PollerFlux} that polls the create composed model operation until it has completed, has failed,
501500
* or has been cancelled. The completed operation returns the created {@link DocumentModelDetails composed model}.
502-
* @throws DocumentModelOperationException If create composed model operation fails and model with
501+
* @throws HttpResponseException If create composed model operation fails and model with
503502
* {@link OperationStatus#FAILED} is created.
504503
* @throws NullPointerException If the list of {@code componentModelIds} is null or empty.
505504
*/
@@ -555,7 +554,7 @@ public PollerFlux<DocumentOperationResult, DocumentModelDetails> beginComposeMod
555554
* creating a composed model.
556555
* @return A {@link PollerFlux} that polls the create composed model operation until it has completed, has failed,
557556
* or has been cancelled. The completed operation returns the copied model {@link DocumentModelDetails}.
558-
* @throws DocumentModelOperationException If create composed model operation fails and model with
557+
* @throws HttpResponseException If create composed model operation fails and model with
559558
* {@link OperationStatus#FAILED} is created.
560559
* @throws NullPointerException If the list of {@code componentModelIds} is null or empty.
561560
*/
@@ -637,7 +636,7 @@ PollerFlux<DocumentOperationResult, DocumentModelDetails> beginComposeModel(List
637636
* generated from the target resource's call to {@link DocumentModelAdministrationAsyncClient#getCopyAuthorization()}
638637
* @return A {@link PollerFlux} that polls the copy model operation until it has completed, has failed,
639638
* or has been cancelled. The completed operation returns the copied model {@link DocumentModelDetails}.
640-
* @throws DocumentModelOperationException If copy operation fails and model with {@link OperationStatus#FAILED} is created.
639+
* @throws HttpResponseException If copy operation fails and model with {@link OperationStatus#FAILED} is created.
641640
* @throws NullPointerException If {@code modelId} or {@code target} is null.
642641
*/
643642
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
@@ -969,7 +968,7 @@ private Mono<PollResponse<DocumentOperationResult>> processBuildingModelResponse
969968
break;
970969
case FAILED:
971970
throw logger.logExceptionAsError(
972-
Transforms.toDocumentModelOperationException(getOperationResponse.getError()));
971+
Transforms.mapResponseErrorToHttpResponseException(getOperationResponse.getError()));
973972
case CANCELED:
974973
default:
975974
status = LongRunningOperationStatus.fromString(

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/administration/DocumentModelAdministrationClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
import com.azure.ai.formrecognizer.administration.models.ModelOperationSummary;
1717
import com.azure.ai.formrecognizer.administration.models.ResourceDetails;
1818
import com.azure.ai.formrecognizer.implementation.models.OperationStatus;
19-
import com.azure.ai.formrecognizer.models.DocumentModelOperationException;
2019
import com.azure.ai.formrecognizer.models.DocumentOperationResult;
2120
import com.azure.core.annotation.ReturnType;
2221
import com.azure.core.annotation.ServiceClient;
2322
import com.azure.core.annotation.ServiceMethod;
23+
import com.azure.core.exception.HttpResponseException;
2424
import com.azure.core.http.rest.PagedIterable;
2525
import com.azure.core.http.rest.Response;
2626
import com.azure.core.util.Context;
@@ -111,7 +111,7 @@ public DocumentAnalysisClient getDocumentAnalysisClient() {
111111
* for more information on building mode for custom documents.
112112
* @return A {@link SyncPoller} that polls the building model operation until it has completed, has failed, or has
113113
* been cancelled. The completed operation returns the trained {@link DocumentModelDetails custom document analysis model}.
114-
* @throws DocumentModelOperationException If building model fails with {@link OperationStatus#FAILED} is created.
114+
* @throws HttpResponseException If building model fails with {@link OperationStatus#FAILED} is created.
115115
* @throws NullPointerException If {@code trainingFilesUrl} is null.
116116
*/
117117
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
@@ -175,7 +175,7 @@ public SyncPoller<DocumentOperationResult, DocumentModelDetails> beginBuildModel
175175
*
176176
* @return A {@link SyncPoller} that polls the building model operation until it has completed, has failed, or has
177177
* been cancelled. The completed operation returns the built {@link DocumentModelDetails custom document analysis model}.
178-
* @throws DocumentModelOperationException If building the model fails with {@link OperationStatus#FAILED} is created.
178+
* @throws HttpResponseException If building the model fails with {@link OperationStatus#FAILED} is created.
179179
* @throws NullPointerException If {@code trainingFilesUrl} is null.
180180
*/
181181
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
@@ -374,7 +374,7 @@ public Response<CopyAuthorization> getCopyAuthorizationWithResponse(
374374
* @param componentModelIds The list of models IDs to form the composed model.
375375
* @return A {@link SyncPoller} that polls the create composed model operation until it has completed, has failed,
376376
* or has been cancelled. The completed operation returns the {@link DocumentModelDetails composed model}.
377-
* @throws DocumentModelOperationException If create composed model operation fails and model with
377+
* @throws HttpResponseException If create composed model operation fails and model with
378378
* {@link OperationStatus#FAILED} is created.
379379
* @throws NullPointerException If the list of {@code componentModelIds} is null or empty.
380380
*/
@@ -433,7 +433,7 @@ public SyncPoller<DocumentOperationResult, DocumentModelDetails> beginComposeMod
433433
*
434434
* @return A {@link SyncPoller} that polls the create composed model operation until it has completed, has failed,
435435
* or has been cancelled. The completed operation returns the {@link DocumentModelDetails composed model}.
436-
* @throws DocumentModelOperationException If create composed model operation fails and model with
436+
* @throws HttpResponseException If create composed model operation fails and model with
437437
* {@link OperationStatus#FAILED} is created.
438438
* @throws NullPointerException If the list of {@code componentModelIds} is null or empty.
439439
*/

0 commit comments

Comments
 (0)