From 4da10b1409866f85bf74da92f294fed6bd123db1 Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Thu, 6 Dec 2018 15:19:01 +0000 Subject: [PATCH] 404s for only source, only tab, and bad resource --- src/api/index.js | 15 +++++++++++++-- src/copy/en.js | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/copy/en.js diff --git a/src/api/index.js b/src/api/index.js index 06d961e..0fcfe04 100755 --- a/src/api/index.js +++ b/src/api/index.js @@ -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() diff --git a/src/copy/en.js b/src/copy/en.js new file mode 100644 index 0000000..d20da49 --- /dev/null +++ b/src/copy/en.js @@ -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.' + } +}