Skip to content

Commit

Permalink
adding exception handling to the UsersController show method
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesiqueira committed Nov 16, 2019
1 parent 14604af commit 73d32b7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ class UsersController < ApplicationController

# GET /users/1
def show
@user = User.find(params[:id].to_i)
render json: @user
begin
@user = User.find(params[:id].to_i)
render json: @user
rescue ActiveRecord::RecordNotFound => e
render json: {
error: e.to_s
}, status: :not_found
end
end

# POST /users V1
Expand Down

0 comments on commit 73d32b7

Please sign in to comment.