File tree Expand file tree Collapse file tree 1 file changed +21
-9
lines changed Expand file tree Collapse file tree 1 file changed +21
-9
lines changed Original file line number Diff line number Diff line change 11
2- import { Response , Request } from "express" ;
2+ import { Response , Request , NextFunction } from "express" ;
33import { logger } from "../logger" ;
44import { AppDataSource } from "../data-source" ;
55import { Course } from "../models/course" ;
66
7- export async function getAllCourses ( request : Request , response : Response ) {
7+ export async function getAllCourses (
8+ request : Request , response : Response , next :NextFunction ) {
89
9- logger . debug ( `Called getAllCourses()` ) ;
10+ try {
1011
11- const courses = await AppDataSource
12- . getRepository ( Course )
13- . createQueryBuilder ( "courses" )
14- . orderBy ( "courses.seqNo" )
15- . getMany ( ) ;
12+ logger . debug ( `Called getAllCourses()` ) ;
13+
14+ throw { error : "Thrown ERROR!" } ;
15+
16+ const courses = await AppDataSource
17+ . getRepository ( Course )
18+ . createQueryBuilder ( "courses" )
19+ . orderBy ( "courses.seqNo" )
20+ . getMany ( ) ;
21+
22+ response . status ( 200 ) . json ( { courses} ) ;
23+
24+ }
25+ catch ( error ) {
26+ logger . error ( `Error calling getAllCourses()` ) ;
27+ return next ( error ) ;
28+ }
1629
17- response . status ( 200 ) . json ( { courses} ) ;
1830
1931}
You can’t perform that action at this time.
0 commit comments