1
- import { describe , expect , it } from 'vitest' ;
1
+ import { describe , expect , it , vi } from 'vitest' ;
2
2
3
3
import { AgentRuntimeErrorType } from '@/libs/agent-runtime' ;
4
4
import { ChatErrorType } from '@/types/fetch' ;
@@ -32,6 +32,30 @@ describe('createErrorResponse', () => {
32
32
expect ( response . status ) . toBe ( 403 ) ;
33
33
} ) ;
34
34
35
+ it ( 'returns a 429 status for InsufficientQuota error type' , ( ) => {
36
+ const errorType = AgentRuntimeErrorType . InsufficientQuota ;
37
+ const response = createErrorResponse ( errorType ) ;
38
+ expect ( response . status ) . toBe ( 429 ) ;
39
+ } ) ;
40
+
41
+ it ( 'returns a 429 status for QuotaLimitReached error type' , ( ) => {
42
+ const errorType = AgentRuntimeErrorType . QuotaLimitReached ;
43
+ const response = createErrorResponse ( errorType ) ;
44
+ expect ( response . status ) . toBe ( 429 ) ;
45
+ } ) ;
46
+
47
+ it ( 'returns a 400 status for ExceededContextWindow error type' , ( ) => {
48
+ const errorType = AgentRuntimeErrorType . ExceededContextWindow ;
49
+ const response = createErrorResponse ( errorType ) ;
50
+ expect ( response . status ) . toBe ( 400 ) ;
51
+ } ) ;
52
+
53
+ it ( 'returns a 400 status for SystemTimeNotMatchError error type' , ( ) => {
54
+ const errorType = ChatErrorType . SystemTimeNotMatchError ;
55
+ const response = createErrorResponse ( errorType ) ;
56
+ expect ( response . status ) . toBe ( 400 ) ;
57
+ } ) ;
58
+
35
59
describe ( 'Provider Biz Error' , ( ) => {
36
60
it ( 'returns a 471 status for ProviderBizError error type' , ( ) => {
37
61
const errorType = AgentRuntimeErrorType . ProviderBizError ;
@@ -44,6 +68,18 @@ describe('createErrorResponse', () => {
44
68
const response = createErrorResponse ( errorType ) ;
45
69
expect ( response . status ) . toBe ( 470 ) ;
46
70
} ) ;
71
+
72
+ it ( 'returns a 472 status for OllamaBizError error type' , ( ) => {
73
+ const errorType = AgentRuntimeErrorType . OllamaBizError ;
74
+ const response = createErrorResponse ( errorType ) ;
75
+ expect ( response . status ) . toBe ( 472 ) ;
76
+ } ) ;
77
+
78
+ it ( 'returns a 472 status for OllamaServiceUnavailable error type' , ( ) => {
79
+ const errorType = ChatErrorType . OllamaServiceUnavailable ;
80
+ const response = createErrorResponse ( errorType ) ;
81
+ expect ( response . status ) . toBe ( 472 ) ;
82
+ } ) ;
47
83
} ) ;
48
84
49
85
// 测试状态码不在200-599范围内的情况
0 commit comments