diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 2762f2c..9a22225 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -19,5 +19,7 @@ class Api::V1::UsersController < Api::V1::BaseController nickname: @steam.nickname } } + rescue ActiveRecord::RecordNotFound + raise ActionController::RoutingError.new('User Not Found') end end diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index 0fa31b2..73f1740 100644 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -23,6 +23,12 @@ describe Api::V1::UsersController do expect(json['steam']).to have_key("url") expect(json['steam']).to have_key("nickname") end + + it 'returns 404 if user does not exist' do + expect { + get :show, id: -1 + }.to raise_error(ActionController::RoutingError) + end end describe '#index' do