Skip to content

Commit 71385a1

Browse files
feat(arkruntime): add exception handle when server response is invalid
1 parent ed1e566 commit 71385a1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

volcengine-java-sdk-ark-runtime/src/main/java/com/volcengine/ark/runtime/utils/ResponseBodyCallback.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.volcengine.ark.runtime.Const;
55
import com.volcengine.ark.runtime.exception.ArkAPIError;
6+
import com.volcengine.ark.runtime.exception.ArkException;
67
import com.volcengine.ark.runtime.exception.ArkHttpException;
78
import com.volcengine.ark.runtime.SSEFormatException;
89
import com.volcengine.ark.runtime.service.ArkService;
@@ -51,11 +52,15 @@ public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response)
5152
if (errorBody == null) {
5253
throw e;
5354
} else {
54-
ArkAPIError error = mapper.readValue(
55-
errorBody.string(),
56-
ArkAPIError.class
57-
);
58-
throw new ArkHttpException(error, e, e.code(), requestId);
55+
try {
56+
ArkAPIError error = mapper.readValue(
57+
errorBody.string(),
58+
ArkAPIError.class
59+
);
60+
throw new ArkHttpException(error, e, e.code(), requestId);
61+
} catch (Exception ignore) {
62+
throw new ArkHttpException(new ArkAPIError(new ArkAPIError.ArkErrorDetails(e.getMessage(), "", "", "InternalServiceError")), e, e.code(), requestId);
63+
}
5964
}
6065
}
6166

0 commit comments

Comments
 (0)