customize Grape API response

868 views Asked by At

I am using Grape GEM in my rails app, How can I customize response if record not found or request params are in valid

@video = Video.where(id: permitted_params[:id]).first!

for example there is no record for any id

1

There are 1 answers

0
Gaurav Gupta On BEST ANSWER

You can do like this:

@video = Video.where(id: permitted_params[:id]).first!
if @video
   #your code
else
  error!({:error_message => "Record Could not found"}, 422)
end