create-hest-app 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
@@ -1,54 +0,0 @@
|
|
1
|
-
import { logger } from '@hestjs/logger';
|
2
|
-
|
3
|
-
// 模拟应用启动时的错误处理
|
4
|
-
async function testErrorScenarios() {
|
5
|
-
console.log('=== Testing Real-world Error Scenarios ===\n');
|
6
|
-
|
7
|
-
// 场景 1: 数据库连接错误
|
8
|
-
try {
|
9
|
-
throw new Error('Database connection failed');
|
10
|
-
} catch (error) {
|
11
|
-
logger.error(
|
12
|
-
'❌ Failed to connect to database:',
|
13
|
-
error instanceof Error ? error : new Error(String(error)),
|
14
|
-
);
|
15
|
-
}
|
16
|
-
|
17
|
-
// 场景 2: API 调用失败
|
18
|
-
try {
|
19
|
-
const apiError = new Error('API request timeout');
|
20
|
-
(apiError as any).status = 504;
|
21
|
-
(apiError as any).endpoint = '/api/users';
|
22
|
-
throw apiError;
|
23
|
-
} catch (error) {
|
24
|
-
logger.error(
|
25
|
-
'❌ API call failed:',
|
26
|
-
error instanceof Error ? error : new Error(String(error)),
|
27
|
-
{
|
28
|
-
requestId: 'req-12345',
|
29
|
-
userId: 'user-67890',
|
30
|
-
},
|
31
|
-
);
|
32
|
-
}
|
33
|
-
|
34
|
-
// 场景 3: 验证错误
|
35
|
-
try {
|
36
|
-
const validationError = new Error('Validation failed');
|
37
|
-
(validationError as any).fields = ['email', 'password'];
|
38
|
-
(validationError as any).code = 'VALIDATION_ERROR';
|
39
|
-
throw validationError;
|
40
|
-
} catch (error) {
|
41
|
-
logger.error(
|
42
|
-
'❌ Validation failed:',
|
43
|
-
error instanceof Error ? error : new Error(String(error)),
|
44
|
-
);
|
45
|
-
}
|
46
|
-
|
47
|
-
// 场景 4: 使用简化的语法
|
48
|
-
const simpleError = new Error('Something went wrong');
|
49
|
-
logger.error('❌ Simple error logging:', simpleError);
|
50
|
-
|
51
|
-
console.log('\n=== Test Complete ===');
|
52
|
-
}
|
53
|
-
|
54
|
-
testErrorScenarios();
|
@@ -1,54 +0,0 @@
|
|
1
|
-
import { logger } from '@hestjs/logger';
|
2
|
-
|
3
|
-
// 模拟应用启动时的错误处理
|
4
|
-
async function testErrorScenarios() {
|
5
|
-
console.log('=== Testing Real-world Error Scenarios ===\n');
|
6
|
-
|
7
|
-
// 场景 1: 数据库连接错误
|
8
|
-
try {
|
9
|
-
throw new Error('Database connection failed');
|
10
|
-
} catch (error) {
|
11
|
-
logger.error(
|
12
|
-
'❌ Failed to connect to database:',
|
13
|
-
error instanceof Error ? error : new Error(String(error)),
|
14
|
-
);
|
15
|
-
}
|
16
|
-
|
17
|
-
// 场景 2: API 调用失败
|
18
|
-
try {
|
19
|
-
const apiError = new Error('API request timeout');
|
20
|
-
(apiError as any).status = 504;
|
21
|
-
(apiError as any).endpoint = '/api/users';
|
22
|
-
throw apiError;
|
23
|
-
} catch (error) {
|
24
|
-
logger.error(
|
25
|
-
'❌ API call failed:',
|
26
|
-
error instanceof Error ? error : new Error(String(error)),
|
27
|
-
{
|
28
|
-
requestId: 'req-12345',
|
29
|
-
userId: 'user-67890',
|
30
|
-
},
|
31
|
-
);
|
32
|
-
}
|
33
|
-
|
34
|
-
// 场景 3: 验证错误
|
35
|
-
try {
|
36
|
-
const validationError = new Error('Validation failed');
|
37
|
-
(validationError as any).fields = ['email', 'password'];
|
38
|
-
(validationError as any).code = 'VALIDATION_ERROR';
|
39
|
-
throw validationError;
|
40
|
-
} catch (error) {
|
41
|
-
logger.error(
|
42
|
-
'❌ Validation failed:',
|
43
|
-
error instanceof Error ? error : new Error(String(error)),
|
44
|
-
);
|
45
|
-
}
|
46
|
-
|
47
|
-
// 场景 4: 使用简化的语法
|
48
|
-
const simpleError = new Error('Something went wrong');
|
49
|
-
logger.error('❌ Simple error logging:', simpleError);
|
50
|
-
|
51
|
-
console.log('\n=== Test Complete ===');
|
52
|
-
}
|
53
|
-
|
54
|
-
testErrorScenarios();
|