customize Grape API response

884 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 best solutions below

0
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