404s for only source, only tab, and bad resource

This commit is contained in:
Lachlan Kermode
2018-12-06 15:19:01 +00:00
parent b0d81b2a6d
commit 4da10b1409
2 changed files with 19 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import { version } from '../../package.json'
import { Router } from 'express'
import copy from '../copy/en'
export default ({ config, controller }) => {
let api = Router()
@@ -30,11 +31,21 @@ export default ({ config, controller }) => {
.retrieve(req.params.source, req.params.tab, req.params.resource)
.then(data => res.json(data))
.catch(err =>
res.status(err.status || 501)
.send()
res.status(err.status || 404)
.send({ error: err })
)
})
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()

6
src/copy/en.js Normal file
View File

@@ -0,0 +1,6 @@
export default {
errors: {
onlySource: 'You cannot query a source directly. The URL needs to be in the format /:source/:tab/:resource.',
onlyTab: 'You cannot query a tab directly. The URL needs to be in the format /:source/:tab/:resource.'
}
}