Skip to content

Commit 30a4fba

Browse files
Merge pull request #225 from 18F/response-v1-notice
include message in object response if v1.1
2 parents 8388e91 + fe2061c commit 30a4fba

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/app.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,18 @@ const filterDownloadResponse = (response, params) => {
5050
const fetchData = (req, res) => {
5151
const params = Object.assign(req.query, req.params);
5252
db.query(params).then(result => {
53-
const response = result.map(dataPoint => Object.assign({
53+
const response = result.map(dataPoint => Object.assign(
54+
{
55+
notice: req.version === '1.1' ? 'v1 is no longer supported. Use v2 instead. See https://analytics.usa.gov/developer' : undefined,
5456
id: dataPoint.id,
5557
date: formatDateForDataPoint(dataPoint),
5658
report_name: dataPoint.report_name,
5759
report_agency: dataPoint.report_agency,
58-
version: dataPoint.version
5960
}, dataPoint.data));
61+
6062
const filteredResponse = filterDownloadResponse(response, params);
6163
res.json(filteredResponse);
64+
6265
}).catch(err => {
6366
console.error('Unexpected Error:', err);
6467
res.status(400);
@@ -77,7 +80,6 @@ app.get('/', (req, res) => {
7780

7881
// middleware
7982
router.use('/v:version/', function(req, res, next) {
80-
console.log('req', req.params.version)
8183
const version = req.params.version;
8284
req.version = version
8385
next();
@@ -102,21 +104,15 @@ routesVersioning({
102104
}, NoMatchFoundCallback));
103105

104106
function NoMatchFoundCallback(req, res) {
105-
res.status(404).send("Version not found. See https://analytics.usa.gov/developer");
107+
res.status(404).json("Version not found. Visit https://analytics.usa.gov/developer for information on the latest supported version.");
106108
}
107109

108110
// v1
109111
function respondV1(req, res) {
110-
req.params.version = '1.1'
111-
// TODO - report this message to response
112-
console.log('v1 is deprecated. Use v2 instead. See https://analytics.usa.gov/developer')
113112
return fetchData(req, res)
114113
}
115114

116115
function respondDomainV1(req, res) {
117-
req.params.version = '1.1'
118-
// TODO - report this message to response
119-
console.log('v1 is deprecated. Use v2 instead. See https://analytics.usa.gov/developer')
120116
return checkDomainFilter(req, res)
121117
}
122118

0 commit comments

Comments
 (0)