centralise msgs in copy/en.js

plus some other fixes
This commit is contained in:
Lachlan Kermode
2018-12-06 16:22:10 +00:00
parent 4da10b1409
commit 72edac944c
6 changed files with 72 additions and 56 deletions

View File

@@ -21,8 +21,8 @@ export default ({ config, controller }) => {
.retrieveFrag(source, tab, resource, frag)
.then(data => res.json(data))
.catch(err =>
res.status(err.status || 501)
.send()
res.status(err.status || 404)
.send({ error: err.message })
)
})
@@ -32,20 +32,10 @@ export default ({ config, controller }) => {
.then(data => res.json(data))
.catch(err =>
res.status(err.status || 404)
.send({ error: err })
.send({ error: err.message })
)
})
api.get('/:source', (req, res) => {
res.status(404)
.send({ error: copy.errors.onlySource })
})
api.get('/:source/:tab', (req, res) => {
res.status(404)
.send({ error: copy.errors.onlyTab })
})
api.get('/update', (req, res) => {
controller
.update()
@@ -55,11 +45,23 @@ export default ({ config, controller }) => {
})
)
.catch(err =>
res.json({
error: err.message
})
res.status(404)
.send({ error: err.message })
)
})
// ERROR routes. Note that it is important that these come AFTER routes
// like /update, so that the regex does not greedily match these routes.
api.get('/:source', (req, res) => {
res.status(404)
.send({ error: copy.errors.onlySource })
})
api.get('/:source/:tab', (req, res) => {
res.status(404)
.send({ error: copy.errors.onlyTab })
})
return api
}