Skip to content

Commit 85764f9

Browse files
authored
Merge pull request #75 from supabase/fix/propagate-error
fix: propagate errors from Postgres
2 parents e4aee2d + a2a0a89 commit 85764f9

File tree

9 files changed

+33
-25
lines changed

9 files changed

+33
-25
lines changed

src/api/columns.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/api/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ router.get('/', async (req, res) => {
1111
return res.status(200).json(data)
1212
} catch (error) {
1313
console.log('throwing error')
14-
res.status(500).json({ error: 'Database error.', status: 500 })
14+
res.status(500).json({ error: error.message })
1515
}
1616
})
1717
router.get('/version', async (req, res) => {
@@ -20,7 +20,7 @@ router.get('/version', async (req, res) => {
2020
return res.status(200).json(data[0]) // only one row
2121
} catch (error) {
2222
console.log('throwing error')
23-
res.status(500).json({ error: 'Database error.', status: 500 })
23+
res.status(500).json({ error: error.message })
2424
}
2525
})
2626

src/api/extensions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ router.get('/', async (req, res) => {
1414
return res.status(200).json(data)
1515
} catch (error) {
1616
console.log('throwing error')
17-
res.status(500).json({ error: 'Database error', status: 500 })
17+
res.status(500).json({ error: error.message })
1818
}
1919
})
2020

@@ -29,7 +29,7 @@ router.post('/', async (req, res) => {
2929
return res.status(200).json(extension)
3030
} catch (error) {
3131
console.log('throwing error')
32-
res.status(500).json({ error: 'Database error', status: 500 })
32+
res.status(400).json({ error: error.message })
3333
}
3434
})
3535

@@ -47,7 +47,7 @@ router.patch('/:name', async (req, res) => {
4747
return res.status(200).json(updated)
4848
} catch (error) {
4949
console.log('throwing error')
50-
res.status(500).json({ error: 'Database error', status: 500 })
50+
res.status(400).json({ error: error.message })
5151
}
5252
})
5353

@@ -65,7 +65,7 @@ router.delete('/:name', async (req, res) => {
6565
return res.status(200).json(deleted)
6666
} catch (error) {
6767
console.log('throwing error')
68-
res.status(500).json({ error: 'Database error', status: 500 })
68+
res.status(400).json({ error: error.message })
6969
}
7070
})
7171

src/api/functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ router.get('/', async (req, res) => {
2424
return res.status(200).json(payload)
2525
} catch (error) {
2626
console.log('throwing error')
27-
res.status(500).json({ error: 'Database error', status: 500 })
27+
res.status(500).json({ error: error.message })
2828
}
2929
})
3030

src/api/policies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ router.get('/', async (req, res) => {
2626
return res.status(200).json(payload)
2727
} catch (error) {
2828
console.log('throwing error', error)
29-
res.status(500).json({ error: 'Database error', status: 500 })
29+
res.status(500).json({ error: error.message })
3030
}
3131
})
3232

@@ -106,7 +106,7 @@ router.delete('/:id', async (req, res) => {
106106
return res.status(200).json(policy)
107107
} catch (error) {
108108
console.log('throwing error', error)
109-
res.status(500).json({ error: 'Database error', status: 500 })
109+
res.status(400).json({ error: error.message })
110110
}
111111
})
112112

src/api/roles.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ router.get('/', async (req, res) => {
3333
return res.status(200).json(payload)
3434
} catch (error) {
3535
console.log('throwing error')
36-
res.status(500).json({ error: 'Database error', status: 500 })
36+
res.status(500).json({ error: error.message })
3737
}
3838
})
3939

@@ -48,7 +48,7 @@ router.post('/', async (req, res) => {
4848
return res.status(200).json(role)
4949
} catch (error) {
5050
console.log('throwing error', error)
51-
res.status(500).json({ error: 'Database error', status: 500 })
51+
res.status(400).json({ error: error.message })
5252
}
5353
})
5454

@@ -68,7 +68,7 @@ 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+
res.status(400).json({ error: error.message })
7272
}
7373
})
7474

@@ -85,7 +85,7 @@ router.delete('/:id', async (req, res) => {
8585
return res.status(200).json(role)
8686
} catch (error) {
8787
console.log('throwing error', error)
88-
res.status(500).json({ error: 'Database error', status: 500 })
88+
res.status(400).json({ error: error.message })
8989
}
9090
})
9191

src/api/schemas.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ router.get('/', async (req, res) => {
2828
return res.status(200).json(payload)
2929
} catch (error) {
3030
console.log('throwing error', error)
31-
res.status(500).json({ error: 'Database error', status: 500 })
31+
res.status(500).json({ error: error.message })
3232
}
3333
})
3434

@@ -48,7 +48,7 @@ router.post('/', async (req, res) => {
4848
return res.status(200).json(schema)
4949
} catch (error) {
5050
console.log('throwing error', error)
51-
res.status(500).json({ error: 'Database error', status: 500 })
51+
res.status(400).json({ error: error.message })
5252
}
5353
})
5454

@@ -80,7 +80,7 @@ router.patch('/:id', async (req, res) => {
8080
return res.status(200).json(updated)
8181
} catch (error) {
8282
console.log('throwing error', error)
83-
res.status(500).json({ error: 'Database error', status: 500 })
83+
res.status(400).json({ error: error.message })
8484
}
8585
})
8686

@@ -97,7 +97,7 @@ router.delete('/:id', async (req, res) => {
9797
return res.status(200).json(schema)
9898
} catch (error) {
9999
console.log('throwing error', error)
100-
res.status(500).json({ error: 'Database error', status: 500 })
100+
res.status(400).json({ error: error.message })
101101
}
102102
})
103103

src/api/tables.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ router.get('/', async (req, res) => {
2626
return res.status(200).json(payload)
2727
} catch (error) {
2828
console.log('throwing error', error)
29-
res.status(500).json({ error: 'Database error', status: 500 })
29+
res.status(500).json({ error: error.message })
3030
}
3131
})
3232

@@ -43,7 +43,7 @@ router.get('/:id', async (req, res) => {
4343
return res.status(200).json(table)
4444
} catch (error) {
4545
console.log('throwing error', error)
46-
res.status(500).json({ error: 'Database error', status: 500 })
46+
res.status(400).json({ error: error.message })
4747
}
4848
})
4949

@@ -119,7 +119,7 @@ router.delete('/:id', async (req, res) => {
119119
return res.status(200).json(table)
120120
} catch (error) {
121121
console.log('throwing error', error)
122-
res.status(500).json({ error: 'Database error', status: 500 })
122+
res.status(400).json({ error: error.message })
123123
}
124124
})
125125

src/api/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ router.get('/', async (req, res) => {
2525
return res.status(200).json(payload)
2626
} catch (error) {
2727
console.log('throwing error')
28-
res.status(500).json({ error: 'Database error.', status: 500 })
28+
res.status(500).json({ error: error.message })
2929
}
3030
})
3131

0 commit comments

Comments
 (0)