@@ -212,7 +212,7 @@ deleteBot cid bot = do
212212 . header " Z-Type" " bot"
213213 . header " Z-Bot" (toByteString' bot)
214214 . header " Z-Conversation" (toByteString' cid)
215- . expect2xx
215+ . expect2xxOr404
216216
217217-- | Calls 'Brig.User.API.Auth.reAuthUserH'.
218218reAuthUser ::
@@ -296,7 +296,7 @@ deleteUser uid = do
296296 brigRequest $
297297 method DELETE
298298 . paths [" /i/users" , toByteString' uid]
299- . expect2xx
299+ . expect2xxOr404
300300
301301-- | Calls 'Brig.API.getContactListH'.
302302getContactList ::
@@ -333,10 +333,12 @@ getUserExportData ::
333333getUserExportData uid = do
334334 resp <-
335335 brigRequest $
336- method GET
336+ check [status200, status404]
337+ . method GET
337338 . paths [" i/users" , toByteString' uid, " export-data" ]
338- . expect2xx
339- decodeBodyOrThrow " brig" resp
339+ if statusCode resp == 404
340+ then pure Nothing
341+ else decodeBodyOrThrow " brig" resp
340342
341343getAccountConferenceCallingConfigClient ::
342344 (Member Rpc r , Member (Input Endpoint ) r , Member (Error ParseException ) r ) =>
@@ -415,7 +417,7 @@ notifyClientsAboutLegalHoldRequest requesterUid targetUid lastPrekey' = do
415417 method POST
416418 . paths [" i" , " clients" , " legalhold" , toByteString' targetUid, " request" ]
417419 . json (LegalHoldClientRequest requesterUid lastPrekey')
418- . expect2xx
420+ . expect2xxOr404
419421
420422-- | Calls 'Brig.User.API.Auth.legalHoldLoginH'.
421423getLegalHoldAuthToken ::
@@ -476,7 +478,7 @@ removeLegalHoldClientFromUser targetUid = do
476478 method DELETE
477479 . paths [" i" , " clients" , " legalhold" , toByteString' targetUid]
478480 . contentJson
479- . expect2xx
481+ . expect2xxOr404
480482
481483-- | Calls 'Brig.API.addClientInternalH'.
482484brigAddClient ::
@@ -579,7 +581,7 @@ createGroupInternal managedBy teamId creatorUserId newGroup = do
579581 method POST
580582 . path " /i/user-groups/full"
581583 . json req
582- if statusCode r >= 200 && statusCode r < 300
584+ if is2xx r
583585 then Right <$> decodeBodyOrThrow @ UserGroup " brig" r
584586 else Left <$> decodeBodyOrThrow @ Wai. Error " brig" r
585587
@@ -592,10 +594,12 @@ getGroupInternal ::
592594getGroupInternal tid gid includeChannels = do
593595 r <-
594596 brigRequest $
595- method GET
597+ check [status200, status404]
598+ . method GET
596599 . paths [" i" , " user-groups" , toByteString' tid, toByteString' gid, toByteString' includeChannels]
597- . expect2xx
598- decodeBodyOrThrow " brig" r
600+ if statusCode r == 404
601+ then pure Nothing
602+ else decodeBodyOrThrow " brig" r
599603
600604getGroupsInternal ::
601605 (Member Rpc r , Member (Input Endpoint ) r , Member (Error ParseException ) r ) =>
@@ -617,16 +621,18 @@ getGroupsInternal tid mbFilter = do
617621 decodeBodyOrThrow " brig" r
618622
619623updateGroup ::
620- (Member Rpc r , Member (Input Endpoint ) r ) =>
624+ (Member Rpc r , Member (Input Endpoint ) r , Member ( Error ParseException ) r ) =>
621625 UpdateGroupInternalRequest ->
622- Sem r ()
623- updateGroup reqBody =
624- void $
626+ Sem r (Either Wai. Error () )
627+ updateGroup reqBody = do
628+ resp <-
625629 brigRequest $
626630 method PUT
627631 . paths [" i" , " user-groups" ]
628632 . json reqBody
629- . expect2xx
633+ if is2xx resp
634+ then pure (Right () )
635+ else Left <$> decodeBodyOrThrow @ Wai. Error " brig" resp
630636
631637deleteGroupInternal ::
632638 ( Member Rpc r ,
@@ -643,7 +649,8 @@ deleteGroupInternal managedBy teamId groupId = do
643649 method DELETE
644650 . paths [" i" , " user-groups" , toByteString' teamId, toByteString' groupId, " managed" , toByteString' managedBy]
645651 case (statusCode resp, errorLabel resp) of
646- (status, _) | status >= 200 && status < 300 -> pure $ Right ()
652+ (status, _) | statusIs2xx status -> pure $ Right ()
653+ (404 , _) -> pure $ Right ()
647654 (403 , Just " user-group-managed-by-mismatch" ) -> pure $ Left DeleteGroupManagedManagedByMismatch
648655 (status, label) ->
649656 throw $
@@ -654,3 +661,9 @@ deleteGroupInternal managedBy teamId groupId = do
654661 where
655662 errorLabel :: ResponseLBS -> Maybe LText
656663 errorLabel = fmap Wai. label . responseJsonMaybe
664+
665+ is2xx :: ResponseLBS -> Bool
666+ is2xx = statusIs2xx . statusCode
667+
668+ statusIs2xx :: Int -> Bool
669+ statusIs2xx s = s >= 200 && s < 300
0 commit comments