|
1 | 1 | package com.databricks.sdk.core.error; |
2 | 2 |
|
3 | 3 | import com.databricks.sdk.core.error.details.ErrorDetails; |
| 4 | +import com.databricks.sdk.core.error.details.ErrorInfo; |
4 | 5 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
5 | 6 | import com.fasterxml.jackson.annotation.JsonProperty; |
6 | | -import java.util.Arrays; |
| 7 | +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
| 8 | +import com.google.auto.value.AutoValue; |
7 | 9 | import java.util.Collections; |
8 | 10 | import java.util.List; |
| 11 | +import javax.annotation.Nullable; |
9 | 12 |
|
10 | 13 | /** |
11 | 14 | * The union of all JSON error responses from the Databricks APIs, not including HTML responses. |
12 | 15 | * |
13 | 16 | * <p>Unknown properties in the response should be ignored. |
14 | 17 | */ |
| 18 | +@AutoValue |
| 19 | +@JsonDeserialize(builder = AutoValue_ApiErrorBody.Builder.class) |
15 | 20 | @JsonIgnoreProperties(ignoreUnknown = true) |
16 | | -public class ApiErrorBody { |
17 | | - private String errorCode; |
18 | | - private String message; |
19 | | - private String scimDetail; |
20 | | - private String scimStatus; |
21 | | - private String scimType; |
22 | | - private String api12Error; |
23 | | - private List<ErrorDetail> errorDetails; |
24 | | - |
25 | | - public ApiErrorBody() {} |
26 | | - |
27 | | - public ApiErrorBody( |
28 | | - @JsonProperty("error_code") String errorCode, |
29 | | - @JsonProperty("message") String message, |
30 | | - @JsonProperty("detail") String scimDetail, |
31 | | - @JsonProperty("status") String scimStatus, |
32 | | - @JsonProperty("scimType") String scimType, |
33 | | - @JsonProperty("error") String api12Error, |
34 | | - @JsonProperty("details") ErrorDetails errorDetails) { |
35 | | - this.errorCode = errorCode; |
36 | | - this.message = message; |
37 | | - this.scimDetail = scimDetail; |
38 | | - this.scimStatus = scimStatus; |
39 | | - this.scimType = scimType; |
40 | | - this.api12Error = api12Error; |
41 | | - this.errorDetails = fromDetails(errorDetails); |
42 | | - } |
43 | | - |
44 | | - public List<ErrorDetail> getErrorDetails() { |
45 | | - return errorDetails; |
46 | | - } |
47 | | - |
48 | | - public void setErrorDetails(List<ErrorDetail> errorDetails) { |
49 | | - this.errorDetails = errorDetails; |
50 | | - } |
51 | | - |
52 | | - public String getErrorCode() { |
53 | | - return errorCode; |
54 | | - } |
55 | | - |
56 | | - public void setErrorCode(String errorCode) { |
57 | | - this.errorCode = errorCode; |
58 | | - } |
59 | | - |
60 | | - public String getMessage() { |
61 | | - return message; |
62 | | - } |
63 | | - |
64 | | - public void setMessage(String message) { |
65 | | - this.message = message; |
66 | | - } |
67 | | - |
68 | | - public String getScimDetail() { |
69 | | - return scimDetail; |
70 | | - } |
71 | | - |
72 | | - public void setScimDetail(String scimDetail) { |
73 | | - this.scimDetail = scimDetail; |
74 | | - } |
75 | | - |
76 | | - public String getScimStatus() { |
77 | | - return scimStatus; |
78 | | - } |
79 | | - |
80 | | - public void setScimStatus(String scimStatus) { |
81 | | - this.scimStatus = scimStatus; |
82 | | - } |
83 | | - |
84 | | - public String getScimType() { |
85 | | - return scimType; |
86 | | - } |
87 | | - |
88 | | - public void setScimType(String scimType) { |
89 | | - this.scimType = scimType; |
90 | | - } |
91 | | - |
92 | | - public String getApi12Error() { |
93 | | - return api12Error; |
94 | | - } |
95 | | - |
96 | | - public void setApi12Error(String api12Error) { |
97 | | - this.api12Error = api12Error; |
98 | | - } |
99 | | - |
100 | | - private static List<ErrorDetail> fromDetails(ErrorDetails details) { |
101 | | - if (details == null) { |
| 21 | +public abstract class ApiErrorBody { |
| 22 | + |
| 23 | + @JsonProperty("error_code") |
| 24 | + @Nullable public abstract String errorCode(); |
| 25 | + |
| 26 | + @JsonProperty("message") |
| 27 | + @Nullable public abstract String message(); |
| 28 | + |
| 29 | + @JsonProperty("detail") |
| 30 | + @Nullable public abstract String scimDetail(); |
| 31 | + |
| 32 | + @JsonProperty("status") |
| 33 | + @Nullable public abstract String scimStatus(); |
| 34 | + |
| 35 | + @JsonProperty("scimType") |
| 36 | + @Nullable public abstract String scimType(); |
| 37 | + |
| 38 | + @JsonProperty("error") |
| 39 | + @Nullable public abstract String api12Error(); |
| 40 | + |
| 41 | + @JsonProperty("details") |
| 42 | + @Nullable public abstract ErrorDetails errorDetails(); |
| 43 | + |
| 44 | + /** |
| 45 | + * Returns a builder for constructing ApiErrorBody instances with the same values as this |
| 46 | + * instance. |
| 47 | + * |
| 48 | + * @return a new builder instance |
| 49 | + */ |
| 50 | + public abstract Builder toBuilder(); |
| 51 | + |
| 52 | + /** |
| 53 | + * Creates a new builder for constructing ApiErrorBody instances. |
| 54 | + * |
| 55 | + * @return a new builder instance |
| 56 | + */ |
| 57 | + public static Builder builder() { |
| 58 | + return new AutoValue_ApiErrorBody.Builder(); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Converts ErrorDetails to a List of legacy ErrorDetail objects for backward compatibility. This |
| 63 | + * method extracts the structured error information and converts it to the format expected by |
| 64 | + * legacy error handling code. |
| 65 | + * |
| 66 | + * @return a list of ErrorDetail objects, or an empty list if errorDetails() is null |
| 67 | + */ |
| 68 | + public List<ErrorDetail> getErrorDetailsList() { |
| 69 | + if (errorDetails() == null) { |
102 | 70 | return Collections.emptyList(); |
103 | 71 | } |
104 | | - if (!details.errorInfo().isPresent()) { |
| 72 | + if (!errorDetails().errorInfo().isPresent()) { |
105 | 73 | return Collections.emptyList(); |
106 | 74 | } |
107 | | - return Arrays.asList( |
| 75 | + |
| 76 | + ErrorInfo errorInfo = errorDetails().errorInfo().get(); |
| 77 | + return Collections.singletonList( |
108 | 78 | new ErrorDetail( |
109 | 79 | "type.googleapis.com/google.rpc.ErrorInfo", |
110 | | - details.errorInfo().get().reason(), |
111 | | - details.errorInfo().get().domain(), |
112 | | - details.errorInfo().get().metadata())); |
| 80 | + errorInfo.reason(), |
| 81 | + errorInfo.domain(), |
| 82 | + errorInfo.metadata())); |
| 83 | + } |
| 84 | + |
| 85 | + /** Builder for constructing ApiErrorBody instances. */ |
| 86 | + @AutoValue.Builder |
| 87 | + @JsonIgnoreProperties(ignoreUnknown = true) |
| 88 | + public abstract static class Builder { |
| 89 | + |
| 90 | + /** |
| 91 | + * Sets the error code. |
| 92 | + * |
| 93 | + * @param errorCode the error code |
| 94 | + * @return this builder for method chaining |
| 95 | + */ |
| 96 | + @JsonProperty("error_code") |
| 97 | + public abstract Builder setErrorCode(@Nullable String errorCode); |
| 98 | + |
| 99 | + /** |
| 100 | + * Sets the message. |
| 101 | + * |
| 102 | + * @param message the message |
| 103 | + * @return this builder for method chaining |
| 104 | + */ |
| 105 | + @JsonProperty("message") |
| 106 | + public abstract Builder setMessage(@Nullable String message); |
| 107 | + |
| 108 | + /** |
| 109 | + * Sets the SCIM detail. |
| 110 | + * |
| 111 | + * @param scimDetail the SCIM detail |
| 112 | + * @return this builder for method chaining |
| 113 | + */ |
| 114 | + @JsonProperty("detail") |
| 115 | + public abstract Builder setScimDetail(@Nullable String scimDetail); |
| 116 | + |
| 117 | + /** |
| 118 | + * Sets the SCIM status. |
| 119 | + * |
| 120 | + * @param scimStatus the SCIM status |
| 121 | + * @return this builder for method chaining |
| 122 | + */ |
| 123 | + @JsonProperty("status") |
| 124 | + public abstract Builder setScimStatus(@Nullable String scimStatus); |
| 125 | + |
| 126 | + /** |
| 127 | + * Sets the SCIM type. |
| 128 | + * |
| 129 | + * @param scimType the SCIM type |
| 130 | + * @return this builder for method chaining |
| 131 | + */ |
| 132 | + @JsonProperty("scimType") |
| 133 | + public abstract Builder setScimType(@Nullable String scimType); |
| 134 | + |
| 135 | + /** |
| 136 | + * Sets the API 1.2 error. |
| 137 | + * |
| 138 | + * @param api12Error the API 1.2 error |
| 139 | + * @return this builder for method chaining |
| 140 | + */ |
| 141 | + @JsonProperty("error") |
| 142 | + public abstract Builder setApi12Error(@Nullable String api12Error); |
| 143 | + |
| 144 | + /** |
| 145 | + * Sets the error details. |
| 146 | + * |
| 147 | + * @param errorDetails the error details |
| 148 | + * @return this builder for method chaining |
| 149 | + */ |
| 150 | + @JsonProperty("details") |
| 151 | + public abstract Builder setErrorDetails(@Nullable ErrorDetails errorDetails); |
| 152 | + |
| 153 | + /** |
| 154 | + * Builds the ApiErrorBody instance. |
| 155 | + * |
| 156 | + * @return a new ApiErrorBody instance |
| 157 | + */ |
| 158 | + public abstract ApiErrorBody build(); |
113 | 159 | } |
114 | 160 | } |
0 commit comments