18F/open-data-maker

negative search distance should report a well-formed json error

dnesting opened this issue · 2 comments

User input can cause an invalid geo squery to be generated:

Stretchy::Errors::ValidationError
…0/gems/stretchy-0.4.7/lib/stretchy/utils/validation.rb:  16:in `validate!'
…gems/stretchy-0.4.7/lib/stretchy/filters/geo_filter.rb:  22:in `initialize'
…stretchy-0.4.7/lib/stretchy/builders/filter_builder.rb:  33:in `new'
…stretchy-0.4.7/lib/stretchy/builders/filter_builder.rb:  33:in `add_geo'
…/stretchy-0.4.7/lib/stretchy/builders/where_builder.rb:  45:in `add_geo'
…ms/stretchy-0.4.7/lib/stretchy/clauses/where_clause.rb: 135:in `geo'
/home/vcap/app/lib/data_magic/query_builder.rb: 132:in `search_location'
/home/vcap/app/lib/data_magic/query_builder.rb:  30:in `generate_squery'
/home/vcap/app/lib/data_magic/query_builder.rb:  13:in `from_params'
/home/vcap/app/lib/data_magic.rb:  69:in `search'

You can cause this to happen with a negative distance (though I don't know if this is the cause of all of the errors), e.g.:

https://collegescorecard.ed.gov/search/?zip=95054&distance=-5&sort=advantage:desc

Error
<h1>Internal Server Error</h1>

There have only been a handful of these errors today (e.g. https://rpm.newrelic.com/accounts/1065766/applications/8349766/traced_errors/819047-8afa292d-5a19-11e5-8d1d-b82a72d2466d). We should give the user an error message, or disregard the distance if it's negative.

related to #192

Note: this can no longer be caused by user input on https://collegescorecard.ed.gov/ but the API should be well-behaved