Error handling - IvanAlvarezEnri/dragon-squad-api GitHub Wiki
Currently in the url that our api has, we can receive multiple parameters in the requests, especially incorrect parameters.
If you send us an incorrect parameter or that does not meet the expected conditions, you will receive a json array with the parameters and the possible cases that it fails.
In this case, for example, locations parameters should be present, have at least three characters and not blank.
min_three_characters = /^.{3,}$/ # => "bar"
params do
requires :location, type: String, regexp: min_three_characters, allow_blank: { value: false, message: 'cannot be blank' }, message: 'is required'
optional :countrycode
end
And this is the json reply you will recieve if the parameter is incorrect. The reply changes for every case. https://dragonsapi.herokuapp.com/api/v1/locations?locatin=ma
[
{
"params": [
"location"
],
"messages": [
"is required",
"cannot be blank"
]
}
]
Thats a situation we want to avoid...