Conversation
…iven parameters & either raises an error or ignores unknown fields Signed-off-by: Shirish Pampoorickal <shirish@mavenlink.com>
…c_validate_params
…c_validate_params
…ted parameters on the endpoint - 'brainstem_validate_params!' validates input parameters against the documented parameters on the endpoint. It raises Brainstem::UnknownParams error when the input params are malformed or unkown params are encountered - 'brainstem_ignore_unknown_params!' returns a sanitized hash while excluding unknown params
…rning sanitized params Signed-off-by: Jason Carter <jason@mavenlink.com>
|
This is awesome. What else needs to happen for this to go in? |
| end | ||
|
|
||
| def sanitize_input_params!(input_params) | ||
| malformed_params_error! unless input_params.is_a?(Hash) && input_params.present? |
There was a problem hiding this comment.
Do we to_h params at some point before this? Otherwise this won't work in Rails 5, since ActionController::Parameters no longer descend from Hash.
EDIT: It looks we call with_indifferent_access on them above. I don't have an environment setup to test that on Rails 5 right now, but I'm not sure if ActionController::Parameters supports that method in 5.
|
@brandonduff I was not very happy with the formatting of the error messages on nested attributes. I would be happy to talk through it if you like. |
|
@shirish-pampoorickal Would love to help if I can. May be fun to pair on. It would be great to start rolling this out in our controllers. I think it could do a lot to standardize error responses when invalid params are passed and save future devs time having to handle it. |
brainstem_validate_params!raises an error if unknown parameters are encountered.