Skip to content

Commit

Permalink
Distinguish different places that throw the same error. (#1229)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx authored Oct 21, 2020
1 parent 22077a1 commit 4208670
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions services/brig/src/Brig/API/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions services/brig/src/Brig/API/Public.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions services/brig/src/Brig/Team/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4208670

Please sign in to comment.