Skip to content

Commit 35bc973

Browse files
author
luk384090-cloud
committed
refactor(errors): rename InternalErrorCode to SdkErrorCode
1 parent 431864c commit 35bc973

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/main/java/com/alibaba/dashscope/agentstudio/AgentStudioException.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Alibaba, Inc. and its affiliates.
22
package com.alibaba.dashscope.agentstudio;
33

4-
import com.alibaba.dashscope.common.InternalErrorCode;
4+
import com.alibaba.dashscope.common.SdkErrorCode;
55
import com.alibaba.dashscope.common.PublicErrorCode;
66
import com.alibaba.dashscope.common.Status;
77
import com.alibaba.dashscope.exception.ApiException;
@@ -134,34 +134,34 @@ public static StatusError statusError(Status status, Throwable cause) {
134134
* Transport failure: {@code APITimeoutError} on socket timeouts, else {@code APIConnectionError}.
135135
*/
136136
public static ConnectionError connectionError(Throwable cause) {
137-
InternalErrorCode def =
137+
SdkErrorCode def =
138138
hasCause(cause, SocketTimeoutException.class)
139-
? InternalErrorCode.SDK_AGENTSTUDIO_API_TIMEOUT_ERROR
140-
: InternalErrorCode.SDK_AGENTSTUDIO_API_CONNECTION_ERROR;
139+
? SdkErrorCode.SDK_AGENTSTUDIO_API_TIMEOUT_ERROR
140+
: SdkErrorCode.SDK_AGENTSTUDIO_API_CONNECTION_ERROR;
141141
String message = causeMessage(cause, def);
142142
return new ConnectionError(
143143
internalStatus(def, message), def.getCode(), message, def.isAllowRetry(), cause);
144144
}
145145

146146
/** A stream read timeout, surfaced as {@code APITimeoutError}. */
147147
public static ConnectionError timeout(String message) {
148-
InternalErrorCode def = InternalErrorCode.SDK_AGENTSTUDIO_API_TIMEOUT_ERROR;
148+
SdkErrorCode def = SdkErrorCode.SDK_AGENTSTUDIO_API_TIMEOUT_ERROR;
149149
String resolved = (message != null && !message.isEmpty()) ? message : def.getMessage();
150150
return new ConnectionError(
151151
internalStatus(def, resolved), def.getCode(), resolved, def.isAllowRetry(), null);
152152
}
153153

154154
/** A fatal SSE protocol error. */
155155
public static StreamError streamError(Throwable cause) {
156-
InternalErrorCode def = InternalErrorCode.SDK_AGENTSTUDIO_STREAM_ERROR;
156+
SdkErrorCode def = SdkErrorCode.SDK_AGENTSTUDIO_STREAM_ERROR;
157157
String message = causeMessage(cause, def);
158158
return new StreamError(
159159
internalStatus(def, message), def.getCode(), message, def.isAllowRetry(), cause);
160160
}
161161

162162
/** Raised when consumers attempt I/O on an already-closed stream. */
163163
public static StreamError streamClosed() {
164-
InternalErrorCode def = InternalErrorCode.SDK_AGENTSTUDIO_STREAM_CLOSED_ERROR;
164+
SdkErrorCode def = SdkErrorCode.SDK_AGENTSTUDIO_STREAM_CLOSED_ERROR;
165165
return new StreamError(
166166
internalStatus(def, def.getMessage()),
167167
def.getCode(),
@@ -213,14 +213,14 @@ private static boolean hasCause(Throwable t, Class<? extends Throwable> type) {
213213
return false;
214214
}
215215

216-
private static String causeMessage(Throwable cause, InternalErrorCode def) {
216+
private static String causeMessage(Throwable cause, SdkErrorCode def) {
217217
if (cause != null && cause.getMessage() != null && !cause.getMessage().isEmpty()) {
218218
return cause.getMessage();
219219
}
220220
return def.getMessage();
221221
}
222222

223-
private static Status internalStatus(InternalErrorCode def, String message) {
223+
private static Status internalStatus(SdkErrorCode def, String message) {
224224
return Status.builder().statusCode(-1).code(def.getCode()).message(message).build();
225225
}
226226

src/main/java/com/alibaba/dashscope/common/InternalErrorCode.java renamed to src/main/java/com/alibaba/dashscope/common/SdkErrorCode.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
// Auto-generated by tools/generate.py -- DO NOT EDIT.
21
package com.alibaba.dashscope.common;
32

43
import java.util.Map;
54

6-
/** Internal error codes with two-layer message design. */
7-
public enum InternalErrorCode {
5+
/** SDK client-side error codes. */
6+
public enum SdkErrorCode {
87
SDK_INVALID_API_KEY(
98
"sdk.InvalidApiKey",
109
PublicErrorCode.AUTH_FAILED,
@@ -314,7 +313,7 @@ public enum InternalErrorCode {
314313
private final String cause;
315314
private final String solution;
316315

317-
InternalErrorCode(
316+
SdkErrorCode(
318317
String code,
319318
PublicErrorCode external,
320319
String message,

0 commit comments

Comments
 (0)