diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 6c02b0b..7f7b78c 100755 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -14,7 +14,8 @@ class Api::V1::UsersController < Api::V1::BaseController end if @user.nil? - raise ActionController::RoutingError.new("User Not Found") + not_found + return end if @user.steamid.present? @@ -44,11 +45,15 @@ class Api::V1::UsersController < Api::V1::BaseController team: @user.team.present? ? { id: @user.team.id, name: @user.team.name } : nil } rescue ActiveRecord::RecordNotFound - raise ActionController::RoutingError.new("User Not Found") + not_found end private + def not_found + render json: {error: "User not found"}, status: :not_found + end + def steam_profile(user) SteamCondenser::Community::SteamId.from_steam_id("STEAM_#{user.steamid}") rescue SteamCondenser::Error diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index da03ea8..86dd3e3 100755 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -78,11 +78,15 @@ describe Api::V1::UsersController do end it "returns 404 if user does not exist" do - expect { get :show, id: -1 }.to raise_error(ActionController::RoutingError) + get :show, id: -1 + expect(response.status).to eq(404) + expect(json["error"]).to eq("User not found") end it "returns 404 if user does not exist by steamid" do - expect { get :show, id: -1, format: "steamid" }.to raise_error(ActionController::RoutingError) + get :show, id: -1, format: "steamid" + expect(response.status).to eq(404) + expect(json["error"]).to eq("User not found") end it "queries the steam condenser for an invalid steamid" do