Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

data.js

25 lines447 Bytes

1const data = []
2​
3function shouldFail() {
4 return Math.random() > 0.7
5}
6​
7export default (req, res) => {
8 if (req.method === 'POST') {
9 const body = JSON.parse(req.body)
10​
11 // sometimes it will fail, this will cause a regression on the UI
12​
13 if (shouldFail()) {
14 throw new Error('Could not add item!')
15 }
16​
17 data.push(body.text.toUpperCase())
18 res.json(data)
19 return
20 }
21​
22 setTimeout(() => {
23 res.json(data)
24 }, 300)