I am using Phoenix as a basic JSON api but I'm having some issues working out how to check that the requester has passed in the correct arguments.
Say the user makes a post request that requires the following body:
{
"user": {
"email": "[email protected]",
"password": "mangoes"
}
}
I want to check that the user has passed in an email and password in the user object. At the moment I'm doing something like this in my controller actions:
params[user][email] and params[user][password]
Surely there is a better way to check for the correct parameters. Maybe something to do with scrub_params? If so how do I return a nice JSON error message instead of the default Internal server error?
Any advice is appreciated.