Skip to content

Commit fcf5ab2

Browse files
committed
Merge branch 'develop'
2 parents eb27094 + ccff7e2 commit fcf5ab2

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/api/policies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ router.post('/', async (req, res) => {
4848
} catch (error) {
4949
// For this one, we always want to give back the error to the customer
5050
console.log('POST error!', error)
51-
res.status(200).json({ error: error.toString(), status: 200 })
51+
res.status(400).json({ error: error.message })
5252
}
5353
})
5454

@@ -85,7 +85,7 @@ router.patch('/:id', async (req, res) => {
8585
} catch (error) {
8686
// For this one, we always want to give back the error to the customer
8787
console.log('Soft error!', error)
88-
res.status(200).json({ error: error.toString(), status: 200 })
88+
res.status(400).json({ error: error.message })
8989
}
9090
})
9191

src/api/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ router.post('/', async (req, res) => {
1111
} catch (error) {
1212
// For this one, we always want to give back the error to the customer
1313
console.log('Soft error!', error)
14-
res.status(200).json({ error: error.toString(), status: 200 })
14+
res.status(400).json({ error: error.message })
1515
}
1616
})
1717

src/api/tables.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ router.post('/', async (req, res) => {
6666
} catch (error) {
6767
// For this one, we always want to give back the error to the customer
6868
console.log('Soft error!', error)
69-
res.status(200).json({ error: error.toString(), status: 200 })
69+
res.status(400).json({ error: error.message })
7070
}
7171
})
7272

@@ -101,7 +101,7 @@ router.patch('/:id', async (req, res) => {
101101
} catch (error) {
102102
// For this one, we always want to give back the error to the customer
103103
console.log('Soft error!', error)
104-
res.status(200).json({ error: error.toString(), status: 200 })
104+
res.status(400).json({ error: error.message })
105105
}
106106
})
107107

test/integration/index.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ describe('When passing an encrypted connection header', () => {
5353
}
5454
})
5555
})
56+
describe('should give meaningful errors', () => {
57+
it('POST', async () => {
58+
try {
59+
const res = await axios.post(`${URL}/query`, { query: 'drop table fake_table' })
60+
assert.equal(res.data.body, 'Code block should not be reached') // Error should be thrown before executing
61+
} catch (error) {
62+
let { status, data } = error.response
63+
assert.equal(status, 400)
64+
assert.equal(data.error, 'error: table "fake_table" does not exist')
65+
}
66+
})
67+
})
5668
describe('/query', () => {
5769
it('POST', async () => {
5870
const res = await axios.post(`${URL}/query`, { query: 'SELECT * FROM USERS' })

0 commit comments

Comments
 (0)