Skip to content

Commit 3951724

Browse files
committed
refactor(deepseek): convert dynamic import to static for handleOpenAIError
Replace dynamic `await import()` with a static import for `handleOpenAIError` in the catch block, and update the error handler test to also assert the HTTP status code (401) on the thrown error. Signed-off-by: daewoongoh <dw.oh@samsung.com>
1 parent 3e640c3 commit 3951724

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/api/providers/__tests__/deepseek.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,10 @@ describe("DeepSeekHandler", () => {
431431
mockCreate.mockRejectedValueOnce(apiError)
432432

433433
const stream = handler.createMessage(systemPrompt, messages)
434-
await expect(stream.next()).rejects.toThrow("DeepSeek completion error: Invalid API key")
434+
const err = await stream.next().catch((e) => e)
435+
436+
expect(err.message).toBe("DeepSeek completion error: Invalid API key")
437+
expect((err as any).status).toBe(401)
435438
})
436439

437440
it("prefers delta.reasoning_content over delta.reasoning when both are present", async () => {

src/api/providers/deepseek.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { convertToR1Format } from "../transform/r1-format"
1818
import { OpenAiHandler } from "./openai"
1919
import { extractReasoningFromDelta } from "./utils/extract-reasoning"
2020
import type { ApiHandlerCreateMessageMetadata } from "../index"
21+
import { handleOpenAIError } from "./utils/error-handler"
2122

2223
// Custom interface for DeepSeek params to support thinking mode
2324
type DeepSeekChatCompletionParams = Omit<OpenAI.Chat.ChatCompletionCreateParamsStreaming, "reasoning_effort"> & {
@@ -137,7 +138,6 @@ export class DeepSeekHandler extends OpenAiHandler {
137138
isAzureAiInference ? { path: OPENAI_AZURE_AI_INFERENCE_PATH } : {},
138139
)
139140
} catch (error) {
140-
const { handleOpenAIError } = await import("./utils/error-handler")
141141
throw handleOpenAIError(error, "DeepSeek")
142142
}
143143

0 commit comments

Comments
 (0)