@@ -26,7 +26,7 @@ router.get('/', async (req, res) => {
2626 return res . status ( 200 ) . json ( payload )
2727 } catch ( error ) {
2828 console . log ( 'throwing error' )
29- res . status ( 500 ) . json ( { error : 'Database error.' , status : 500 } )
29+ res . status ( 500 ) . json ( { error : error . message } )
3030 }
3131} )
3232
@@ -50,7 +50,7 @@ router.post('/', async (req, res) => {
5050 return res . status ( 200 ) . json ( column )
5151 } catch ( error ) {
5252 console . log ( 'throwing error' , error )
53- res . status ( 500 ) . json ( { error : 'Database error' , status : 500 } )
53+ res . status ( 400 ) . json ( { error : error . message } )
5454 }
5555} )
5656
@@ -68,7 +68,11 @@ router.patch('/:id', async (req, res) => {
6868 return res . status ( 200 ) . json ( updated )
6969 } catch ( error ) {
7070 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+ }
7276 }
7377} )
7478
@@ -85,7 +89,11 @@ router.delete('/:id', async (req, res) => {
8589 return res . status ( 200 ) . json ( column )
8690 } catch ( error ) {
8791 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+ }
8997 }
9098} )
9199
0 commit comments