Skip to content
Closed
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 @@ -28,14 +28,14 @@ public DatabricksError apply(Response resp, ApiErrorBody errorBody) {
"Overriding error with {} (original status code: {}, original error code: {})",
override.getDebugName(),
resp.getStatusCode(),
errorBody.getErrorCode());
errorBody.errorCode());
return override.makeError(errorBody);
}
}
int code = resp.getStatusCode();
String message = errorBody.getMessage();
String errorCode = errorBody.getErrorCode();
List<ErrorDetail> details = errorBody.getErrorDetails();
String message = errorBody.message();
String errorCode = errorBody.errorCode();
List<ErrorDetail> details = errorBody.getErrorDetailsList();
if (errorCodeMapping.containsKey(errorCode)) {
return errorCodeMapping.get(errorCode).create(message, details);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,131 +1,178 @@
package com.databricks.sdk.core.error;

import com.databricks.sdk.core.error.details.ErrorDetails;
import com.databricks.sdk.core.error.details.ErrorInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Arrays;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.auto.value.AutoValue;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;

/**
* The union of all JSON error responses from the Databricks APIs, not including HTML responses.
*
* <p>Unknown properties in the response should be ignored.
*/
@AutoValue
@JsonDeserialize(builder = AutoValue_ApiErrorBody.Builder.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ApiErrorBody {
private String errorCode;
private String message;
private String scimDetail;
private String scimStatus;
private String scimType;
private String api12Error;
private List<ErrorDetail> errorDetails;
public abstract class ApiErrorBody {

public ApiErrorBody() {}
@JsonProperty("error_code")
@Nullable public abstract String errorCode();

/**
* Constructs an ApiErrorBody from the given parameters.
*
* <p>The error details are converted to a list of ErrorDetail objects. This only supports the
* ErrorInfo type.
*
* @param errorCode The error code.
* @param message The error message.
* @param scimDetail The SCIM detail.
*/
public ApiErrorBody(
@JsonProperty("error_code") String errorCode,
@JsonProperty("message") String message,
@JsonProperty("detail") String scimDetail,
@JsonProperty("status") String scimStatus,
@JsonProperty("scimType") String scimType,
@JsonProperty("error") String api12Error,
@JsonProperty("details") ErrorDetails errorDetails) {
this.errorCode = errorCode;
this.message = message;
this.scimDetail = scimDetail;
this.scimStatus = scimStatus;
this.scimType = scimType;
this.api12Error = api12Error;
this.errorDetails = fromDetails(errorDetails);
}
@JsonProperty("message")
@Nullable public abstract String message();

public List<ErrorDetail> getErrorDetails() {
return errorDetails;
}
@JsonProperty("detail")
@Nullable public abstract String scimDetail();

public void setErrorDetails(List<ErrorDetail> errorDetails) {
this.errorDetails = errorDetails;
}
@JsonProperty("status")
@Nullable public abstract String scimStatus();

public String getErrorCode() {
return errorCode;
}
@JsonProperty("scimType")
@Nullable public abstract String scimType();

public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
@JsonProperty("error")
@Nullable public abstract String api12Error();

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public String getScimDetail() {
return scimDetail;
}

public void setScimDetail(String scimDetail) {
this.scimDetail = scimDetail;
}
@JsonProperty("details")
@Nullable public abstract ErrorDetails errorDetails();

public String getScimStatus() {
return scimStatus;
}
@JsonProperty("errorDetailsList")
@Nullable public abstract List<ErrorDetail> errorDetailsList();

public void setScimStatus(String scimStatus) {
this.scimStatus = scimStatus;
}

public String getScimType() {
return scimType;
}

public void setScimType(String scimType) {
this.scimType = scimType;
}

public String getApi12Error() {
return api12Error;
}
/**
* Returns a builder for constructing ApiErrorBody instances with the same values as this
* instance.
*
* @return a new builder instance
*/
public abstract Builder toBuilder();

public void setApi12Error(String api12Error) {
this.api12Error = api12Error;
/**
* Creates a new builder for constructing ApiErrorBody instances.
*
* @return a new builder instance
*/
public static Builder builder() {
return new AutoValue_ApiErrorBody.Builder();
}

/**
* Converts the error details to a list of ErrorDetail objects. This only supports the ErrorInfo
* type.
* Converts ErrorDetails to a List of legacy ErrorDetail objects for backward compatibility. This
* method extracts the structured error information and converts it to the format expected by
* legacy error handling code.
*
* @param details The error details to convert.
* @return A list of ErrorDetail objects.
* @return a list of ErrorDetail objects, or an empty list if errorDetails() is null
*/
private static List<ErrorDetail> fromDetails(ErrorDetails details) {
if (details == null) {
public List<ErrorDetail> getErrorDetailsList() {
// If we have a direct errorDetailsList from JSON, use it
if (errorDetailsList() != null) {
return errorDetailsList();
}

// Fallback to converting from ErrorDetails for backward compatibility
if (errorDetails() == null) {
return Collections.emptyList();
}
if (!details.errorInfo().isPresent()) {
if (!errorDetails().errorInfo().isPresent()) {
return Collections.emptyList();
}
return Arrays.asList(

ErrorInfo errorInfo = errorDetails().errorInfo().get();
return Collections.singletonList(
new ErrorDetail(
"type.googleapis.com/google.rpc.ErrorInfo",
details.errorInfo().get().reason(),
details.errorInfo().get().domain(),
details.errorInfo().get().metadata()));
errorInfo.reason(),
errorInfo.domain(),
errorInfo.metadata()));
}

/** Builder for constructing ApiErrorBody instances. */
@AutoValue.Builder
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract static class Builder {

/**
* Sets the error code.
*
* @param errorCode the error code
* @return this builder for method chaining
*/
@JsonProperty("error_code")
public abstract Builder setErrorCode(@Nullable String errorCode);

/**
* Sets the message.
*
* @param message the message
* @return this builder for method chaining
*/
@JsonProperty("message")
public abstract Builder setMessage(@Nullable String message);

/**
* Sets the SCIM detail.
*
* @param scimDetail the SCIM detail
* @return this builder for method chaining
*/
@JsonProperty("detail")
public abstract Builder setScimDetail(@Nullable String scimDetail);

/**
* Sets the SCIM status.
*
* @param scimStatus the SCIM status
* @return this builder for method chaining
*/
@JsonProperty("status")
public abstract Builder setScimStatus(@Nullable String scimStatus);

/**
* Sets the SCIM type.
*
* @param scimType the SCIM type
* @return this builder for method chaining
*/
@JsonProperty("scimType")
public abstract Builder setScimType(@Nullable String scimType);

/**
* Sets the API 1.2 error.
*
* @param api12Error the API 1.2 error
* @return this builder for method chaining
*/
@JsonProperty("error")
public abstract Builder setApi12Error(@Nullable String api12Error);

/**
* Sets the error details.
*
* @param errorDetails the error details
* @return this builder for method chaining
*/
@JsonProperty("details")
public abstract Builder setErrorDetails(@Nullable ErrorDetails errorDetails);

/**
* Sets the error details list.
*
* @param errorDetailsList the error details list
* @return this builder for method chaining
*/
@JsonProperty("errorDetailsList")
public abstract Builder setErrorDetailsList(@Nullable List<ErrorDetail> errorDetailsList);

/**
* Builds the ApiErrorBody instance.
*
* @return a new ApiErrorBody instance
*/
public abstract ApiErrorBody build();
}
}
Loading
Loading