From d2d4090e278171253a18a15bc0c51ac1890305d3 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 12 Nov 2021 13:54:26 +0100 Subject: [PATCH] :bug: Don't raise exception when profile is not found. --- backend/src/app/rpc/queries/profile.clj | 13 +++++++++---- backend/test/app/services_profile_test.clj | 8 +++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/src/app/rpc/queries/profile.clj b/backend/src/app/rpc/queries/profile.clj index b68c6a5f1..a3ca758f5 100644 --- a/backend/src/app/rpc/queries/profile.clj +++ b/backend/src/app/rpc/queries/profile.clj @@ -37,10 +37,15 @@ (sv/defmethod ::profile {:auth false} [{:keys [pool] :as cfg} {:keys [profile-id] :as params}] - (if profile-id - (retrieve-profile pool profile-id) - {:id uuid/zero - :fullname "Anonymous User"})) + + ;; We need to return the anonymous profile object in two cases, when + ;; no profile-id is in session, and when db call raises not found. In all other + ;; cases we need to reraise the exception. + (or (ex/try* + #(some->> profile-id (retrieve-profile pool)) + #(when (not= :not-found (:type (ex-data %))) (throw %))) + {:id uuid/zero + :fullname "Anonymous User"})) (def ^:private sql:default-profile-team "select t.id, name diff --git a/backend/test/app/services_profile_test.clj b/backend/test/app/services_profile_test.clj index b51bcd8c0..ba82c0f0e 100644 --- a/backend/test/app/services_profile_test.clj +++ b/backend/test/app/services_profile_test.clj @@ -6,6 +6,7 @@ (ns app.services-profile-test (:require + [app.common.uuid :as uuid] [app.db :as db] [app.rpc.mutations.profile :as profile] [app.test-helpers :as th] @@ -153,11 +154,8 @@ :profile-id (:id prof)} out (th/query! params)] ;; (th/print-result! out) - (let [error (:error out) - error-data (ex-data error)] - (t/is (th/ex-info? error)) - (t/is (= (:type error-data) :not-found)))) - )) + (let [result (:result out)] + (t/is (= uuid/zero (:id result))))))) (t/deftest registration-domain-whitelist (let [whitelist #{"gmail.com" "hey.com" "ya.ru"}]