From 88ad0c09e94d40e01e9a4a07bcf396f76359a01c Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 20 Oct 2020 14:57:35 +0200 Subject: [PATCH] Distinguish different places that throw the same error. --- services/brig/src/Brig/API/Error.hs | 12 ++++++------ services/brig/src/Brig/API/Public.hs | 4 ++-- services/brig/src/Brig/Team/API.hs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/services/brig/src/Brig/API/Error.hs b/services/brig/src/Brig/API/Error.hs index 2835c60c57a..e96ddf050ac 100644 --- a/services/brig/src/Brig/API/Error.hs +++ b/services/brig/src/Brig/API/Error.hs @@ -67,7 +67,7 @@ connError TooManyConnections {} = StdError connectionLimitReached connError InvalidTransition {} = StdError invalidTransition connError NotConnected {} = StdError notConnected connError InvalidUser {} = StdError invalidUser -connError ConnectNoIdentity {} = StdError noIdentity +connError ConnectNoIdentity {} = StdError (noIdentity 0) connError (ConnectBlacklistedUserKey k) = StdError $ foldKey (const blacklistedEmail) (const blacklistedPhone) k connError (ConnectInvalidEmail _ _) = StdError invalidEmail connError ConnectInvalidPhone {} = StdError invalidPhone @@ -123,11 +123,11 @@ changePhoneError (PhoneExists _) = StdError userKeyExists changePwError :: ChangePasswordError -> Error changePwError InvalidCurrentPassword = StdError badCredentials -changePwError ChangePasswordNoIdentity = StdError noIdentity +changePwError ChangePasswordNoIdentity = StdError (noIdentity 1) changePwError ChangePasswordMustDiffer = StdError changePasswordMustDiffer changeHandleError :: ChangeHandleError -> Error -changeHandleError ChangeHandleNoIdentity = StdError noIdentity +changeHandleError ChangeHandleNoIdentity = StdError (noIdentity 2) changeHandleError ChangeHandleExists = StdError handleExists changeHandleError ChangeHandleInvalid = StdError invalidHandle @@ -179,7 +179,7 @@ clientError ClientLegalHoldCannotBeAdded = StdError can'tAddLegalHoldClient idtError :: RemoveIdentityError -> Error idtError LastIdentity = StdError lastIdentity idtError NoPassword = StdError noPassword -idtError NoIdentity = StdError noIdentity +idtError NoIdentity = StdError (noIdentity 3) propDataError :: PropertiesDataError -> Error propDataError TooManyProperties = StdError tooManyProperties @@ -241,8 +241,8 @@ invalidTransition = Wai.Error status403 "bad-conn-update" "Invalid status transi notConnected :: Wai.Error notConnected = Wai.Error status403 "no-connection" "No connection exists between users." -noIdentity :: Wai.Error -noIdentity = Wai.Error status403 "no-identity" "The user has no verified identity (email or phone number)." +noIdentity :: Int -> Wai.Error +noIdentity i = Wai.Error status403 "no-identity" ("The user has no verified identity (email or phone number). [code: " <> cs (show i) <> "]") noEmail :: Wai.Error noEmail = Wai.Error status403 "no-email" "This operation requires the user to have a verified email address." diff --git a/services/brig/src/Brig/API/Public.hs b/services/brig/src/Brig/API/Public.hs index f5d2f51ff0f..8fa022a4c94 100644 --- a/services/brig/src/Brig/API/Public.hs +++ b/services/brig/src/Brig/API/Public.hs @@ -334,7 +334,7 @@ sitemap o = do Doc.description "JSON body" Doc.response 200 "Password changed." Doc.end Doc.errorResponse badCredentials - Doc.errorResponse noIdentity + Doc.errorResponse (noIdentity 4) put "/self/locale" (continue changeLocaleH) $ zauthUserId @@ -451,7 +451,7 @@ sitemap o = do Doc.response 201 "The connection was created." Doc.end Doc.errorResponse connectionLimitReached Doc.errorResponse invalidUser - Doc.errorResponse noIdentity + Doc.errorResponse (noIdentity 5) get "/connections" (continue listConnectionsH) $ accept "application" "json" diff --git a/services/brig/src/Brig/Team/API.hs b/services/brig/src/Brig/Team/API.hs index 9aff2cb2759..36ba98e281f 100644 --- a/services/brig/src/Brig/Team/API.hs +++ b/services/brig/src/Brig/Team/API.hs @@ -80,7 +80,7 @@ routesPublic = do Doc.returns (Doc.ref Public.modelTeamInvitation) Doc.response 201 "Invitation was created and sent." Doc.end Doc.errorResponse noEmail - Doc.errorResponse noIdentity + Doc.errorResponse (noIdentity 6) Doc.errorResponse invalidEmail Doc.errorResponse blacklistedEmail Doc.errorResponse tooManyTeamInvitations @@ -215,7 +215,7 @@ createInvitation uid tid body = do let inviteePerms = Team.rolePermissions inviteeRole inviteeRole = fromMaybe Team.defaultRole . irRole $ body inviter <- do - idt <- maybe (throwStd noIdentity) return =<< lift (fetchUserIdentity uid) + idt <- maybe (throwStd (noIdentity 7)) return =<< lift (fetchUserIdentity uid) from <- maybe (throwStd noEmail) return (emailIdentity idt) ensurePermissionToAddUser uid tid inviteePerms pure $ CreateInvitationInviter uid from