Skip to content

Commit

Permalink
Show status 400 if the request contains errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sashachabin committed Jul 27, 2022
1 parent 6328ccb commit 385caf2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ http
let queryWithoutQuotes = query.replace(/'/g, '')
let region = extractRegionFromQuery(query) || GLOBAL_REGION

res.writeHead(200, {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/json'
})

try {
let browsers = await getBrowsers(queryWithoutQuotes, region)
res.writeHead(200, {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/json'
})
res.write(JSON.stringify(browsers))
res.end()
} catch (error) {
res.writeHead(400, {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/json'
})
res.write(JSON.stringify({ error }))
res.end()
}
Expand Down

0 comments on commit 385caf2

Please sign in to comment.