@@ -26,7 +26,7 @@ router.get('/', async (req, res) => {
26
26
return res . status ( 200 ) . json ( payload )
27
27
} catch ( error ) {
28
28
console . log ( 'throwing error' )
29
- res . status ( 500 ) . json ( { error : 'Database error.' , status : 500 } )
29
+ res . status ( 500 ) . json ( { error : error . message } )
30
30
}
31
31
} )
32
32
@@ -50,7 +50,7 @@ router.post('/', async (req, res) => {
50
50
return res . status ( 200 ) . json ( column )
51
51
} catch ( error ) {
52
52
console . log ( 'throwing error' , error )
53
- res . status ( 500 ) . json ( { error : 'Database error' , status : 500 } )
53
+ res . status ( 400 ) . json ( { error : error . message } )
54
54
}
55
55
} )
56
56
@@ -68,7 +68,11 @@ router.patch('/:id', async (req, res) => {
68
68
return res . status ( 200 ) . json ( updated )
69
69
} catch ( error ) {
70
70
console . log ( 'throwing error' , error )
71
- res . status ( 500 ) . json ( { error : 'Database error' , status : 500 } )
71
+ if ( error instanceof TypeError ) {
72
+ res . status ( 404 ) . json ( { error : 'Cannot find a column with that id' } )
73
+ } else {
74
+ res . status ( 400 ) . json ( { error : error . message } )
75
+ }
72
76
}
73
77
} )
74
78
@@ -85,7 +89,11 @@ router.delete('/:id', async (req, res) => {
85
89
return res . status ( 200 ) . json ( column )
86
90
} catch ( error ) {
87
91
console . log ( 'throwing error' , error )
88
- res . status ( 500 ) . json ( { error : 'Database error' , status : 500 } )
92
+ if ( error instanceof TypeError ) {
93
+ res . status ( 404 ) . json ( { error : 'Cannot find a column with that id' } )
94
+ } else {
95
+ res . status ( 400 ) . json ( { error : error . message } )
96
+ }
89
97
}
90
98
} )
91
99
0 commit comments