create-hest-app 0.1.2 → 0.1.4
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
@@ -45,31 +45,6 @@ async function bootstrap() {
|
|
45
45
|
},
|
46
46
|
);
|
47
47
|
|
48
|
-
// 可选:仍然支持手动指定控制器的方式
|
49
|
-
// app.useScalarWithControllers(
|
50
|
-
// [AppController, UserController], // 传入需要生成文档的控制器
|
51
|
-
// {
|
52
|
-
// info: {
|
53
|
-
// title: 'HestJS CQRS Demo API',
|
54
|
-
// version: '1.0.0',
|
55
|
-
// description:
|
56
|
-
// 'A demonstration of HestJS CQRS framework capabilities with Scalar API documentation',
|
57
|
-
// },
|
58
|
-
// servers: [
|
59
|
-
// {
|
60
|
-
// url: 'http://localhost:3002',
|
61
|
-
// description: 'Development server',
|
62
|
-
// },
|
63
|
-
// ],
|
64
|
-
// },
|
65
|
-
// {
|
66
|
-
// path: '/docs',
|
67
|
-
// theme: 'elysia', // 使用elysia主题
|
68
|
-
// enableMarkdown: true,
|
69
|
-
// markdownPath: '/api-docs.md',
|
70
|
-
// },
|
71
|
-
// );
|
72
|
-
|
73
48
|
logger.info('📚 API Documentation available at:');
|
74
49
|
logger.info(' • Scalar UI: http://localhost:3002/docs');
|
75
50
|
logger.info(' • OpenAPI JSON: http://localhost:3002/openapi.json');
|
@@ -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();
|