From c609ae3ccf1b2986846ce44c58c666645d343c70 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 2 Oct 2015 15:10:24 +0200 Subject: [PATCH] http friendly status codes. resolves #321 --- app.js | 3 +- controller/place.js | 2 +- controller/search.js | 2 +- middleware/404.js | 2 +- middleware/408.js | 15 -------- middleware/sendJSON.js | 37 +++++++++++++++++-- routes/v1.js | 2 +- sanitiser/sanitizeAll.js | 2 +- .../focus_point_invalid_lat.coffee | 4 +- .../focus_point_invalid_lon.coffee | 4 +- .../focus_point_missing_lat.coffee | 2 +- .../focus_point_missing_lon.coffee | 2 +- test/ciao/autocomplete/no_params.coffee | 4 +- test/ciao/autocomplete/text_invalid.coffee | 4 +- test/ciao/place/missing_id.coffee | 2 +- .../boundary_circle_invalid_radius.coffee | 2 +- .../boundary_country_invalid_alpha2.coffee | 4 +- .../boundary_country_invalid_alpha3.coffee | 4 +- .../boundary_country_invalid_iso3166.coffee | 4 +- .../reverse/duplicate_parameter_name.coffee | 2 +- test/ciao/reverse/layers_invalid.coffee | 2 +- .../reverse/layers_mix_invalid_valid.coffee | 2 +- test/ciao/reverse/non_scalar_parameter.coffee | 2 +- test/ciao/reverse/point_invalid_lat.coffee | 4 +- test/ciao/reverse/point_invalid_lon.coffee | 4 +- test/ciao/reverse/point_missing_lat.coffee | 2 +- test/ciao/reverse/point_missing_lon.coffee | 2 +- test/ciao/reverse/sources_invalid.coffee | 4 +- .../sources_layers_invalid_combo.coffee | 2 +- ...undary_circle_invalid_lat_lon_types.coffee | 4 +- .../boundary_circle_invalid_radius.coffee | 2 +- .../search/boundary_circle_missing_lat.coffee | 2 +- .../search/boundary_circle_missing_lon.coffee | 2 +- .../boundary_country_invalid_alpha2.coffee | 4 +- .../boundary_country_invalid_alpha3.coffee | 4 +- .../boundary_country_invalid_iso3166.coffee | 4 +- .../boundary_rect_partially_specified.coffee | 2 +- .../search/focus_point_invalid_lat.coffee | 4 +- .../search/focus_point_invalid_lon.coffee | 4 +- .../search/focus_point_missing_lat.coffee | 2 +- .../search/focus_point_missing_lon.coffee | 2 +- test/ciao/search/layers_invalid.coffee | 2 +- .../search/layers_mix_invalid_valid.coffee | 2 +- test/ciao/search/no_params.coffee | 4 +- test/ciao/search/sources_invalid.coffee | 4 +- .../sources_layers_invalid_combo.coffee | 2 +- test/ciao/search/text_invalid.coffee | 4 +- test/ciao/search/text_valid.coffee | 2 +- 48 files changed, 99 insertions(+), 84 deletions(-) delete mode 100644 middleware/408.js diff --git a/app.js b/app.js index 241c0920..d05e0365 100644 --- a/app.js +++ b/app.js @@ -26,7 +26,6 @@ v1.addRoutes(app, peliasConfig); /** ----------------------- error middleware ----------------------- **/ app.use( require('./middleware/404') ); -app.use( require('./middleware/408') ); app.use( require('./middleware/500') ); -module.exports = app; \ No newline at end of file +module.exports = app; diff --git a/controller/place.js b/controller/place.js index e24be2fc..2a4462cc 100644 --- a/controller/place.js +++ b/controller/place.js @@ -29,7 +29,7 @@ function setup( backend ){ // error handler if( err ){ - req.errors.push( err.message ? err.message : err ); + req.errors.push( err ); } // set response data else { diff --git a/controller/search.js b/controller/search.js index 795ad2c6..93767713 100644 --- a/controller/search.js +++ b/controller/search.js @@ -31,7 +31,7 @@ function setup( backend, query ){ // error handler if( err ){ - req.errors.push( err.message ? err.message : err ); + req.errors.push( err ); } // set response data else { diff --git a/middleware/404.js b/middleware/404.js index 85d81c70..65c25467 100644 --- a/middleware/404.js +++ b/middleware/404.js @@ -5,4 +5,4 @@ function middleware(req, res) { res.status(404).json({ error: 'not found: invalid path' }); } -module.exports = middleware; \ No newline at end of file +module.exports = middleware; diff --git a/middleware/408.js b/middleware/408.js deleted file mode 100644 index 8e57eb28..00000000 --- a/middleware/408.js +++ /dev/null @@ -1,15 +0,0 @@ - -// handle time out errors -function middleware(err, req, res, next) { - res.header('Cache-Control','public'); - var error = (err && err.message) ? err.message : err; - - if( res.statusCode === 408 || (error.toLowerCase().indexOf('request timeout') !== -1) ){ - res.status(408); - res.json({ error: typeof error === 'string' ? error : 'request timeout' }); - } else { - next(err); - } -} - -module.exports = middleware; \ No newline at end of file diff --git a/middleware/sendJSON.js b/middleware/sendJSON.js index 9ec3e733..94353c6c 100644 --- a/middleware/sendJSON.js +++ b/middleware/sendJSON.js @@ -1,12 +1,43 @@ +var check = require('check-types'); + function sendJSONResponse(req, res, next) { // do nothing if no result data set - if (!res || !res.body) { + if (!res || !check.object(res.body) || !check.object(res.body.geocoding)) { return next(); } + // default status + var statusCode = 200; + + // vary status code whenever an error was reported + var geocoding = res.body.geocoding; + if( check.array( geocoding.errors ) && geocoding.errors.length ){ + + // default status for errors is 400 Bad Request + statusCode = 400; // 400 Bad Request + + // iterate over all reported errors + geocoding.errors.forEach( function( err ){ + // custom status codes for instances of the Error() object. + if( err instanceof Error ){ + // we can extract the error type from the constructor name + switch( err.constructor.name ){ + // elasticsearch errors + // see: https://github.com/elastic/elasticsearch-js/blob/master/src/lib/errors.js + case 'RequestTimeout': statusCode = 408; break; // 408 Request Timeout + case 'NoConnections': statusCode = 502; break; // 502 Bad Gateway + case 'ConnectionFault': statusCode = 502; break; // 502 Bad Gateway + case 'Serialization': statusCode = 500; break; // 500 Internal Server Error + case 'Generic': statusCode = 500; break; // 500 Internal Server Error + default: statusCode = 500; // 500 Internal Server Error + } + } + }); + } + // respond - return res.status(200).json(res.body); + return res.status(statusCode).json(res.body); } -module.exports = sendJSONResponse; \ No newline at end of file +module.exports = sendJSONResponse; diff --git a/routes/v1.js b/routes/v1.js index 352f7c82..397fea21 100644 --- a/routes/v1.js +++ b/routes/v1.js @@ -17,7 +17,7 @@ var middleware = { /** ----------------------- controllers ----------------------- **/ -var controllers = { +var controllers = { mdToHTML: require('../controller/markdownToHtml'), place: require('../controller/place'), search: require('../controller/search'), diff --git a/sanitiser/sanitizeAll.js b/sanitiser/sanitizeAll.js index 1c2dd2af..ac31ddfe 100644 --- a/sanitiser/sanitizeAll.js +++ b/sanitiser/sanitizeAll.js @@ -36,4 +36,4 @@ function sanitize( req, sanitizers, cb ){ } // export function -module.exports = sanitize; \ No newline at end of file +module.exports = sanitize; diff --git a/test/ciao/autocomplete/focus_point_invalid_lat.coffee b/test/ciao/autocomplete/focus_point_invalid_lat.coffee index 37a86593..532bd965 100644 --- a/test/ciao/autocomplete/focus_point_invalid_lat.coffee +++ b/test/ciao/autocomplete/focus_point_invalid_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/autocomplete?text=a&focus.point.lat=foo&focus.point.lon=-73.990342' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['focus.point.lat'] -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/autocomplete/focus_point_invalid_lon.coffee b/test/ciao/autocomplete/focus_point_invalid_lon.coffee index 74779437..04f689d4 100644 --- a/test/ciao/autocomplete/focus_point_invalid_lon.coffee +++ b/test/ciao/autocomplete/focus_point_invalid_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/autocomplete?text=a&focus.point.lat=40.744243&focus.point.lon=' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 json.geocoding.query['focus.point.lat'].should.eql 40.744243 -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/autocomplete/focus_point_missing_lat.coffee b/test/ciao/autocomplete/focus_point_missing_lat.coffee index 300a3bd5..beb17c4d 100644 --- a/test/ciao/autocomplete/focus_point_missing_lat.coffee +++ b/test/ciao/autocomplete/focus_point_missing_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/autocomplete?text=a&focus.point.lon=-73.990342' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/autocomplete/focus_point_missing_lon.coffee b/test/ciao/autocomplete/focus_point_missing_lon.coffee index fc1e507b..c99b23f8 100644 --- a/test/ciao/autocomplete/focus_point_missing_lon.coffee +++ b/test/ciao/autocomplete/focus_point_missing_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/autocomplete?text=a&focus.point.lat=40.744243' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/autocomplete/no_params.coffee b/test/ciao/autocomplete/no_params.coffee index 5feb9923..216ca9fb 100644 --- a/test/ciao/autocomplete/no_params.coffee +++ b/test/ciao/autocomplete/no_params.coffee @@ -3,7 +3,7 @@ path: '/v1/autocomplete' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -30,4 +30,4 @@ json.geocoding.errors.should.eql [ 'invalid param \'text\': text length, must be should.not.exist json.geocoding.warnings #? inputs -json.geocoding.query['size'].should.eql 10 \ No newline at end of file +json.geocoding.query['size'].should.eql 10 diff --git a/test/ciao/autocomplete/text_invalid.coffee b/test/ciao/autocomplete/text_invalid.coffee index 8b0e5dc6..3be2faaf 100644 --- a/test/ciao/autocomplete/text_invalid.coffee +++ b/test/ciao/autocomplete/text_invalid.coffee @@ -3,7 +3,7 @@ path: '/v1/autocomplete?text=' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs should.not.exist json.geocoding.query['text'] -json.geocoding.query['size'].should.eql 10 \ No newline at end of file +json.geocoding.query['size'].should.eql 10 diff --git a/test/ciao/place/missing_id.coffee b/test/ciao/place/missing_id.coffee index 1fc8ed18..2b525196 100644 --- a/test/ciao/place/missing_id.coffee +++ b/test/ciao/place/missing_id.coffee @@ -3,7 +3,7 @@ path: '/v1/place' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/boundary_circle_invalid_radius.coffee b/test/ciao/reverse/boundary_circle_invalid_radius.coffee index 386ff167..cb257d4e 100644 --- a/test/ciao/reverse/boundary_circle_invalid_radius.coffee +++ b/test/ciao/reverse/boundary_circle_invalid_radius.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=40.744243&point.lon=-73.990342&boundary.circle.radius=foo' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/boundary_country_invalid_alpha2.coffee b/test/ciao/reverse/boundary_country_invalid_alpha2.coffee index 5f6e6a13..aced0b50 100644 --- a/test/ciao/reverse/boundary_country_invalid_alpha2.coffee +++ b/test/ciao/reverse/boundary_country_invalid_alpha2.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=1&boundary.country=ZZ' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 -should.not.exist json.geocoding.query['boundary.country'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.country'] diff --git a/test/ciao/reverse/boundary_country_invalid_alpha3.coffee b/test/ciao/reverse/boundary_country_invalid_alpha3.coffee index 3ef9e841..0335a77f 100644 --- a/test/ciao/reverse/boundary_country_invalid_alpha3.coffee +++ b/test/ciao/reverse/boundary_country_invalid_alpha3.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=1&boundary.country=ZZZ' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 -should.not.exist json.geocoding.query['boundary.country'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.country'] diff --git a/test/ciao/reverse/boundary_country_invalid_iso3166.coffee b/test/ciao/reverse/boundary_country_invalid_iso3166.coffee index 05130a9b..cabfbf6e 100644 --- a/test/ciao/reverse/boundary_country_invalid_iso3166.coffee +++ b/test/ciao/reverse/boundary_country_invalid_iso3166.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=1&boundary.country=FOOBAR' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 -should.not.exist json.geocoding.query['boundary.country'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.country'] diff --git a/test/ciao/reverse/duplicate_parameter_name.coffee b/test/ciao/reverse/duplicate_parameter_name.coffee index c38c4da6..701f8e83 100644 --- a/test/ciao/reverse/duplicate_parameter_name.coffee +++ b/test/ciao/reverse/duplicate_parameter_name.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=1¶m=value1¶m=value2' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/layers_invalid.coffee b/test/ciao/reverse/layers_invalid.coffee index c4d858fc..354efb02 100644 --- a/test/ciao/reverse/layers_invalid.coffee +++ b/test/ciao/reverse/layers_invalid.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=2&layers=notlayer' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/layers_mix_invalid_valid.coffee b/test/ciao/reverse/layers_mix_invalid_valid.coffee index 71a95fa4..a636a26b 100644 --- a/test/ciao/reverse/layers_mix_invalid_valid.coffee +++ b/test/ciao/reverse/layers_mix_invalid_valid.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=2&layers=country,notlayer' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/non_scalar_parameter.coffee b/test/ciao/reverse/non_scalar_parameter.coffee index 158c80b2..757761e4 100644 --- a/test/ciao/reverse/non_scalar_parameter.coffee +++ b/test/ciao/reverse/non_scalar_parameter.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=1¶meter[idx]=value' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/point_invalid_lat.coffee b/test/ciao/reverse/point_invalid_lat.coffee index 3f085880..52d13b90 100644 --- a/test/ciao/reverse/point_invalid_lat.coffee +++ b/test/ciao/reverse/point_invalid_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=foo&point.lon=-73.990342' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['point.lat'] -should.not.exist json.geocoding.query['point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['point.lon'] diff --git a/test/ciao/reverse/point_invalid_lon.coffee b/test/ciao/reverse/point_invalid_lon.coffee index e7e6b436..29c49e01 100644 --- a/test/ciao/reverse/point_invalid_lon.coffee +++ b/test/ciao/reverse/point_invalid_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=40.744243&point.lon=' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 json.geocoding.query['point.lat'].should.eql 40.744243 -should.not.exist json.geocoding.query['point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['point.lon'] diff --git a/test/ciao/reverse/point_missing_lat.coffee b/test/ciao/reverse/point_missing_lat.coffee index 7cd2f44a..f1ffe173 100644 --- a/test/ciao/reverse/point_missing_lat.coffee +++ b/test/ciao/reverse/point_missing_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lon=-73.990342' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/point_missing_lon.coffee b/test/ciao/reverse/point_missing_lon.coffee index a206726a..b7792b12 100644 --- a/test/ciao/reverse/point_missing_lon.coffee +++ b/test/ciao/reverse/point_missing_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=40.744243' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/reverse/sources_invalid.coffee b/test/ciao/reverse/sources_invalid.coffee index e464cfe4..bdc6c826 100644 --- a/test/ciao/reverse/sources_invalid.coffee +++ b/test/ciao/reverse/sources_invalid.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=2&sources=openstreetmap,notasource' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['types'] -should.not.exist json.geocoding.query['type'] \ No newline at end of file +should.not.exist json.geocoding.query['type'] diff --git a/test/ciao/reverse/sources_layers_invalid_combo.coffee b/test/ciao/reverse/sources_layers_invalid_combo.coffee index b15fcc88..17de70ca 100644 --- a/test/ciao/reverse/sources_layers_invalid_combo.coffee +++ b/test/ciao/reverse/sources_layers_invalid_combo.coffee @@ -3,7 +3,7 @@ path: '/v1/reverse?point.lat=1&point.lon=2&sources=quattroshapes&layers=address' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/boundary_circle_invalid_lat_lon_types.coffee b/test/ciao/search/boundary_circle_invalid_lat_lon_types.coffee index 0a4ba5ec..2e57214f 100644 --- a/test/ciao/search/boundary_circle_invalid_lat_lon_types.coffee +++ b/test/ciao/search/boundary_circle_invalid_lat_lon_types.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.circle.lat=foo&boundary.circle.lon=bar' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -34,4 +34,4 @@ json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['boundary.circle.lat'] should.not.exist json.geocoding.query['boundary.circle.lon'] -should.not.exist json.geocoding.query['boundary.circle.radius'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.circle.radius'] diff --git a/test/ciao/search/boundary_circle_invalid_radius.coffee b/test/ciao/search/boundary_circle_invalid_radius.coffee index 67c573b6..7302d723 100644 --- a/test/ciao/search/boundary_circle_invalid_radius.coffee +++ b/test/ciao/search/boundary_circle_invalid_radius.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.circle.lat=40.744243&boundary.circle.lon=-73.990342&boundary.circle.radius=foo' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/boundary_circle_missing_lat.coffee b/test/ciao/search/boundary_circle_missing_lat.coffee index e46b079a..ec0ba9ed 100644 --- a/test/ciao/search/boundary_circle_missing_lat.coffee +++ b/test/ciao/search/boundary_circle_missing_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.circle.lon=-73.990342&boundary.circle.radius=100' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/boundary_circle_missing_lon.coffee b/test/ciao/search/boundary_circle_missing_lon.coffee index 45bc0120..d873031d 100644 --- a/test/ciao/search/boundary_circle_missing_lon.coffee +++ b/test/ciao/search/boundary_circle_missing_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.circle.lat=40.744243&boundary.circle.radius=100' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/boundary_country_invalid_alpha2.coffee b/test/ciao/search/boundary_country_invalid_alpha2.coffee index 06c73b6a..0f28b808 100644 --- a/test/ciao/search/boundary_country_invalid_alpha2.coffee +++ b/test/ciao/search/boundary_country_invalid_alpha2.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.country=ZZ' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 -should.not.exist json.geocoding.query['boundary.country'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.country'] diff --git a/test/ciao/search/boundary_country_invalid_alpha3.coffee b/test/ciao/search/boundary_country_invalid_alpha3.coffee index bd518281..c317aff2 100644 --- a/test/ciao/search/boundary_country_invalid_alpha3.coffee +++ b/test/ciao/search/boundary_country_invalid_alpha3.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.country=ZZZ' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 -should.not.exist json.geocoding.query['boundary.country'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.country'] diff --git a/test/ciao/search/boundary_country_invalid_iso3166.coffee b/test/ciao/search/boundary_country_invalid_iso3166.coffee index 9f8c9d6b..3cf6728a 100644 --- a/test/ciao/search/boundary_country_invalid_iso3166.coffee +++ b/test/ciao/search/boundary_country_invalid_iso3166.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.country=FOOBAR' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 -should.not.exist json.geocoding.query['boundary.country'] \ No newline at end of file +should.not.exist json.geocoding.query['boundary.country'] diff --git a/test/ciao/search/boundary_rect_partially_specified.coffee b/test/ciao/search/boundary_rect_partially_specified.coffee index 0c0e72e1..7334620b 100644 --- a/test/ciao/search/boundary_rect_partially_specified.coffee +++ b/test/ciao/search/boundary_rect_partially_specified.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&boundary.rect.min_lat=-40.659' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/focus_point_invalid_lat.coffee b/test/ciao/search/focus_point_invalid_lat.coffee index 39df4df6..800d25cc 100644 --- a/test/ciao/search/focus_point_invalid_lat.coffee +++ b/test/ciao/search/focus_point_invalid_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&focus.point.lat=foo&focus.point.lon=-73.990342' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['focus.point.lat'] -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/search/focus_point_invalid_lon.coffee b/test/ciao/search/focus_point_invalid_lon.coffee index da69a8fc..8e72e42a 100644 --- a/test/ciao/search/focus_point_invalid_lon.coffee +++ b/test/ciao/search/focus_point_invalid_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&focus.point.lat=40.744243&focus.point.lon=' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 json.geocoding.query['focus.point.lat'].should.eql 40.744243 -should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file +should.not.exist json.geocoding.query['focus.point.lon'] diff --git a/test/ciao/search/focus_point_missing_lat.coffee b/test/ciao/search/focus_point_missing_lat.coffee index 6e534133..f97f638f 100644 --- a/test/ciao/search/focus_point_missing_lat.coffee +++ b/test/ciao/search/focus_point_missing_lat.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&focus.point.lon=-73.990342' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/focus_point_missing_lon.coffee b/test/ciao/search/focus_point_missing_lon.coffee index cf81b267..2094b7d1 100644 --- a/test/ciao/search/focus_point_missing_lon.coffee +++ b/test/ciao/search/focus_point_missing_lon.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&focus.point.lat=40.744243' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/layers_invalid.coffee b/test/ciao/search/layers_invalid.coffee index 3a7c9d38..ec9c58bd 100644 --- a/test/ciao/search/layers_invalid.coffee +++ b/test/ciao/search/layers_invalid.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&layers=notlayer' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/layers_mix_invalid_valid.coffee b/test/ciao/search/layers_mix_invalid_valid.coffee index c1a53645..fab29ef2 100644 --- a/test/ciao/search/layers_mix_invalid_valid.coffee +++ b/test/ciao/search/layers_mix_invalid_valid.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&layers=country,notlayer' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/no_params.coffee b/test/ciao/search/no_params.coffee index e374c6aa..e1b192aa 100644 --- a/test/ciao/search/no_params.coffee +++ b/test/ciao/search/no_params.coffee @@ -3,7 +3,7 @@ path: '/v1/search' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -30,4 +30,4 @@ json.geocoding.errors.should.eql [ 'invalid param \'text\': text length, must be should.not.exist json.geocoding.warnings #? inputs -json.geocoding.query['size'].should.eql 10 \ No newline at end of file +json.geocoding.query['size'].should.eql 10 diff --git a/test/ciao/search/sources_invalid.coffee b/test/ciao/search/sources_invalid.coffee index 9f346faf..2114c9c0 100644 --- a/test/ciao/search/sources_invalid.coffee +++ b/test/ciao/search/sources_invalid.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&sources=openstreetmap,notasource' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings json.geocoding.query['text'].should.eql 'a' json.geocoding.query['size'].should.eql 10 should.not.exist json.geocoding.query['types'] -should.not.exist json.geocoding.query['type'] \ No newline at end of file +should.not.exist json.geocoding.query['type'] diff --git a/test/ciao/search/sources_layers_invalid_combo.coffee b/test/ciao/search/sources_layers_invalid_combo.coffee index fb01cdf7..c0f84b13 100644 --- a/test/ciao/search/sources_layers_invalid_combo.coffee +++ b/test/ciao/search/sources_layers_invalid_combo.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=a&sources=quattroshapes&layers=address' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' diff --git a/test/ciao/search/text_invalid.coffee b/test/ciao/search/text_invalid.coffee index d50f6dea..67fe7da8 100644 --- a/test/ciao/search/text_invalid.coffee +++ b/test/ciao/search/text_invalid.coffee @@ -3,7 +3,7 @@ path: '/v1/search?text=' #? 200 ok -response.statusCode.should.be.equal 200 +response.statusCode.should.be.equal 400 response.should.have.header 'charset', 'utf8' response.should.have.header 'content-type', 'application/json; charset=utf-8' @@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings #? inputs should.not.exist json.geocoding.query['text'] -json.geocoding.query['size'].should.eql 10 \ No newline at end of file +json.geocoding.query['size'].should.eql 10 diff --git a/test/ciao/search/text_valid.coffee b/test/ciao/search/text_valid.coffee index 039fe8f8..e3214d08 100644 --- a/test/ciao/search/text_valid.coffee +++ b/test/ciao/search/text_valid.coffee @@ -30,4 +30,4 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' -json.geocoding.query['size'].should.eql 10 \ No newline at end of file +json.geocoding.query['size'].should.eql 10