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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
138 changes: 74 additions & 64 deletions eng/emitter-package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion eng/emitter-package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"main": "dist/src/index.js",
"dependencies": {
"@azure-tools/typespec-java": "0.49.1"
"@azure-tools/typespec-java": "0.49.2"
},
"devDependencies": {
"@azure-tools/typespec-autorest": "0.74.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.polling.AsyncPollResponse;
import com.azure.core.util.polling.LongRunningOperationStatus;
import com.azure.core.util.polling.PollResponse;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.core.util.serializer.SerializerAdapter;
Expand Down Expand Up @@ -231,6 +232,24 @@ public <T, U> SyncPoller<PollResult<T>, U> getLroResult(Response<BinaryData> act
defaultPollInterval, () -> activationResponse, context);
}

/**
* Waits for completion and gets the final result, or throws an error.
*
* @param poller the synchronous poller.
* @param <T> type of poll result.
* @param <U> type of final result.
* @return the final result.
* @throws ManagementException if the long running operation fails.
*/
public <T, U> U getLroFinalResultOrError(SyncPoller<PollResult<T>, U> poller) {
PollResponse<PollResult<T>> response = poller.waitForCompletion();
ManagementException exception = getLroException(response.getStatus(), response.getValue());
if (exception != null) {
throw exception;
}
return poller.getFinalResult();
}

/**
* Gets the final result, or an error, based on last async poll response.
*
Expand All @@ -240,17 +259,25 @@ public <T, U> SyncPoller<PollResult<T>, U> getLroResult(Response<BinaryData> act
* @return the final result, or an error.
*/
public <T, U> Mono<U> getLroFinalResultOrError(AsyncPollResponse<PollResult<T>, U> response) {
if (response.getStatus() != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) {
ManagementException exception = getLroException(response.getStatus(), response.getValue());
if (exception != null) {
return Mono.error(exception);
}
return response.getFinalResult();
}

private ManagementException getLroException(LongRunningOperationStatus status, PollResult<?> result) {
PollResult.Error lroError = result == null ? null : result.getError();
if (status != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED || lroError != null) {
String errorMessage;
ManagementError managementError = null;
HttpResponse errorResponse = null;
PollResult.Error lroError = response.getValue().getError();
if (lroError != null) {
errorResponse = new HttpResponseImpl(lroError.getResponseStatusCode(), lroError.getResponseHeaders(),
lroError.getResponseBody());

errorMessage = response.getValue().getError().getMessage();
String errorBody = response.getValue().getError().getResponseBody();
errorMessage = lroError.getMessage();
String errorBody = lroError.getResponseBody();
if (errorBody != null) {
// try to deserialize error body to ManagementError
try {
Expand All @@ -269,12 +296,11 @@ public <T, U> Mono<U> getLroFinalResultOrError(AsyncPollResponse<PollResult<T>,
}
if (managementError == null) {
// fallback to default ManagementError
managementError = new ManagementError(response.getStatus().toString(), errorMessage);
managementError = new ManagementError(status.toString(), errorMessage);
}
return Mono.error(new ManagementException(errorMessage, errorResponse, managementError));
} else {
return response.getFinalResult();
return new ManagementException(errorMessage, errorResponse, managementError);
}
return null;
}

private static final class HttpResponseImpl extends HttpResponse {
Expand Down
Loading
Loading