|
1 | 1 | // Copyright (c) Alibaba, Inc. and its affiliates. |
2 | 2 | package com.alibaba.dashscope.agentstudio; |
3 | 3 |
|
4 | | -import com.alibaba.dashscope.common.InternalErrorCode; |
| 4 | +import com.alibaba.dashscope.common.SdkErrorCode; |
5 | 5 | import com.alibaba.dashscope.common.PublicErrorCode; |
6 | 6 | import com.alibaba.dashscope.common.Status; |
7 | 7 | import com.alibaba.dashscope.exception.ApiException; |
@@ -134,34 +134,34 @@ public static StatusError statusError(Status status, Throwable cause) { |
134 | 134 | * Transport failure: {@code APITimeoutError} on socket timeouts, else {@code APIConnectionError}. |
135 | 135 | */ |
136 | 136 | public static ConnectionError connectionError(Throwable cause) { |
137 | | - InternalErrorCode def = |
| 137 | + SdkErrorCode def = |
138 | 138 | 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; |
141 | 141 | String message = causeMessage(cause, def); |
142 | 142 | return new ConnectionError( |
143 | 143 | internalStatus(def, message), def.getCode(), message, def.isAllowRetry(), cause); |
144 | 144 | } |
145 | 145 |
|
146 | 146 | /** A stream read timeout, surfaced as {@code APITimeoutError}. */ |
147 | 147 | public static ConnectionError timeout(String message) { |
148 | | - InternalErrorCode def = InternalErrorCode.SDK_AGENTSTUDIO_API_TIMEOUT_ERROR; |
| 148 | + SdkErrorCode def = SdkErrorCode.SDK_AGENTSTUDIO_API_TIMEOUT_ERROR; |
149 | 149 | String resolved = (message != null && !message.isEmpty()) ? message : def.getMessage(); |
150 | 150 | return new ConnectionError( |
151 | 151 | internalStatus(def, resolved), def.getCode(), resolved, def.isAllowRetry(), null); |
152 | 152 | } |
153 | 153 |
|
154 | 154 | /** A fatal SSE protocol error. */ |
155 | 155 | public static StreamError streamError(Throwable cause) { |
156 | | - InternalErrorCode def = InternalErrorCode.SDK_AGENTSTUDIO_STREAM_ERROR; |
| 156 | + SdkErrorCode def = SdkErrorCode.SDK_AGENTSTUDIO_STREAM_ERROR; |
157 | 157 | String message = causeMessage(cause, def); |
158 | 158 | return new StreamError( |
159 | 159 | internalStatus(def, message), def.getCode(), message, def.isAllowRetry(), cause); |
160 | 160 | } |
161 | 161 |
|
162 | 162 | /** Raised when consumers attempt I/O on an already-closed stream. */ |
163 | 163 | public static StreamError streamClosed() { |
164 | | - InternalErrorCode def = InternalErrorCode.SDK_AGENTSTUDIO_STREAM_CLOSED_ERROR; |
| 164 | + SdkErrorCode def = SdkErrorCode.SDK_AGENTSTUDIO_STREAM_CLOSED_ERROR; |
165 | 165 | return new StreamError( |
166 | 166 | internalStatus(def, def.getMessage()), |
167 | 167 | def.getCode(), |
@@ -213,14 +213,14 @@ private static boolean hasCause(Throwable t, Class<? extends Throwable> type) { |
213 | 213 | return false; |
214 | 214 | } |
215 | 215 |
|
216 | | - private static String causeMessage(Throwable cause, InternalErrorCode def) { |
| 216 | + private static String causeMessage(Throwable cause, SdkErrorCode def) { |
217 | 217 | if (cause != null && cause.getMessage() != null && !cause.getMessage().isEmpty()) { |
218 | 218 | return cause.getMessage(); |
219 | 219 | } |
220 | 220 | return def.getMessage(); |
221 | 221 | } |
222 | 222 |
|
223 | | - private static Status internalStatus(InternalErrorCode def, String message) { |
| 223 | + private static Status internalStatus(SdkErrorCode def, String message) { |
224 | 224 | return Status.builder().statusCode(-1).code(def.getCode()).message(message).build(); |
225 | 225 | } |
226 | 226 |
|
|
0 commit comments