Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HttpResponseError based on arch board feedback #23910

Merged
merged 3 commits into from
Sep 7, 2021
Merged
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
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.models;
package com.azure.core.experimental.models;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -64,7 +64,7 @@ public String getMessage() {
*
* @return the target of this error.
*/
public String getTarget() {
String getTarget() {
return target;
}

Expand All @@ -74,7 +74,7 @@ public String getTarget() {
* @param target the target of this error.
* @return the updated {@link HttpResponseError} instance.
*/
public HttpResponseError setTarget(String target) {
HttpResponseError setTarget(String target) {
this.target = target;
return this;
}
Expand All @@ -84,7 +84,7 @@ public HttpResponseError setTarget(String target) {
*
* @return the inner error for this error.
*/
public HttpResponseInnerError getInnerError() {
HttpResponseInnerError getInnerError() {
return innerError;
}

Expand All @@ -93,7 +93,7 @@ public HttpResponseInnerError getInnerError() {
* @param innerError the inner error for this error.
* @return the updated {@link HttpResponseError} instance.
*/
public HttpResponseError setInnerError(HttpResponseInnerError innerError) {
HttpResponseError setInnerError(HttpResponseInnerError innerError) {
this.innerError = innerError;
return this;
}
Expand All @@ -103,7 +103,7 @@ public HttpResponseError setInnerError(HttpResponseInnerError innerError) {
*
* @return the error details.
*/
public List<HttpResponseError> getErrorDetails() {
List<HttpResponseError> getErrorDetails() {
return errorDetails;
}

Expand All @@ -113,7 +113,7 @@ public List<HttpResponseError> getErrorDetails() {
* @param errorDetails the error details.
* @return the updated {@link HttpResponseError} instance.
*/
public HttpResponseError setErrorDetails(List<HttpResponseError> errorDetails) {
HttpResponseError setErrorDetails(List<HttpResponseError> errorDetails) {
this.errorDetails = errorDetails;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.models;
package com.azure.core.experimental.models;


import com.fasterxml.jackson.annotation.JsonProperty;

/**
* The inner error of a {@link HttpResponseError}.
*/
public final class HttpResponseInnerError {
final class HttpResponseInnerError {

@JsonProperty(value = "code")
private String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.azure.core.exception;

import com.azure.core.http.HttpResponse;
import com.azure.core.models.HttpResponseError;

/**
* The exception thrown when an unsuccessful response is received with http status code (e.g. 3XX, 4XX, 5XX) from the
Expand Down Expand Up @@ -70,19 +69,6 @@ public HttpResponseException(final String message, final HttpResponse response,
this.response = response;
}

/**
* Initializes a new instance of the HttpResponseException class.
*
* @param message The exception message.
* @param response The {@link HttpResponse} received that is associated to the exception.
* @param error The {@link HttpResponseError} associated with this exception.
*/
public HttpResponseException(final String message, final HttpResponse response, final HttpResponseError error) {
super(message);
this.value = error;
this.response = response;
}

/**
* Initializes a new instance of the HttpResponseException class.
*
Expand Down Expand Up @@ -125,22 +111,6 @@ public HttpResponse getResponse() {
public Object getValue() {
return value;
}

/**
* Returns the {@link HttpResponseError} containing the error details that caused this exception.
*
* @return The {@link HttpResponseError} containing the error details that caused this exception.
* @throws IllegalStateException if the error details cannot be mapped to an instance of {@link HttpResponseError}.
*/
public HttpResponseError getError() {
if (value == null) {
return null;
}
if (value instanceof HttpResponseError) {
return (HttpResponseError) value;
}
return null;
}
}


2 changes: 1 addition & 1 deletion sdk/monitor/azure-monitor-query/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-experimental</artifactId>
<version>1.0.0-beta.17</version> <!-- {x-version-update;com.azure:azure-core-experimental;dependency} -->
<version>1.0.0-beta.18</version> <!-- {x-version-update;unreleased_com.azure:azure-core-experimental;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.experimental.models.HttpResponseError;
import com.azure.core.experimental.models.TimeInterval;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.models.HttpResponseError;
import com.azure.core.util.BinaryData;
import com.azure.core.util.Context;
import com.azure.core.util.CoreUtils;
Expand Down Expand Up @@ -39,10 +39,8 @@

import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import static com.azure.core.util.FluxUtil.withContext;

Expand Down Expand Up @@ -249,15 +247,6 @@ private Response<LogsBatchQueryResults> convertToLogQueryBatchResult(Response<Ba

private HttpResponseError mapLogsQueryError(ErrorInfo errors) {
if (errors != null) {
List<HttpResponseError> errorDetails = Collections.emptyList();
if (errors.getDetails() != null) {
errorDetails = errors.getDetails()
.stream()
.map(errorDetail -> new HttpResponseError(errorDetail.getCode(), errorDetail.getMessage())
.setTarget(errorDetail.getTarget()))
.collect(Collectors.toList());
}

ErrorInfo innerError = errors.getInnererror();
ErrorInfo currentError = errors.getInnererror();
while (currentError != null) {
Expand All @@ -268,7 +257,7 @@ private HttpResponseError mapLogsQueryError(ErrorInfo errors) {
if (errors.getCode() != null && innerError != null && errors.getCode().equals(innerError.getCode())) {
code = innerError.getCode();
}
return new HttpResponseError(code, errors.getMessage()).setErrorDetails(errorDetails);
return new HttpResponseError(code, errors.getMessage());
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.experimental.models.HttpResponseError;
import com.azure.core.experimental.models.TimeInterval;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.models.HttpResponseError;
import com.azure.core.util.Context;
import com.azure.core.util.CoreUtils;
import com.azure.monitor.query.implementation.metrics.models.Metric;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package com.azure.monitor.query.models;

import com.azure.core.annotation.Immutable;
import com.azure.core.models.HttpResponseError;
import com.azure.core.experimental.models.HttpResponseError;
import com.azure.core.util.BinaryData;
import com.azure.core.util.CoreUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package com.azure.monitor.query.models;

import com.azure.core.annotation.Immutable;
import com.azure.core.models.HttpResponseError;
import com.azure.core.experimental.models.HttpResponseError;
import com.azure.core.util.BinaryData;
import com.azure.core.util.logging.ClientLogger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package com.azure.monitor.query.models;

import com.azure.core.annotation.Immutable;
import com.azure.core.models.HttpResponseError;
import com.azure.core.experimental.models.HttpResponseError;

import java.util.List;

Expand Down