Implement fetchAPIDOrH using a dedicated error type
This commit is contained in:
parent
25fcceabde
commit
7c2fad7417
1 changed files with 28 additions and 11 deletions
|
@ -709,6 +709,33 @@ fetchAPID m getId h lu = first showError <$> fetchAPID' m getId h lu
|
|||
showError Nothing = "Object @id doesn't match the URI we fetched"
|
||||
showError (Just e) = displayException e
|
||||
|
||||
data FetchAPError
|
||||
= FetchAPErrorGet APGetError
|
||||
-- Object @id doesn't match the URI we fetched
|
||||
| FetchAPErrorIdMismatch
|
||||
-- Object @id URI's host doesn't match the URI we fetched
|
||||
| FetchAPErrorHostMismatch
|
||||
deriving Show
|
||||
|
||||
fetchAPIDOrH'
|
||||
:: (MonadIO m, ActivityPub a, ActivityPub b)
|
||||
=> Manager
|
||||
-> (a -> LocalURI)
|
||||
-> Text
|
||||
-> LocalURI
|
||||
-> ExceptT FetchAPError m (Either a b)
|
||||
fetchAPIDOrH' m getId h lu = do
|
||||
e <- withExceptT FetchAPErrorGet $ fetchAP' m $ l2f h lu
|
||||
case e of
|
||||
Left' (Doc h' x) ->
|
||||
if h == h' && getId x == lu
|
||||
then return $ Left x
|
||||
else throwE FetchAPErrorIdMismatch
|
||||
Right' (Doc h' y) ->
|
||||
if h == h'
|
||||
then return $ Right y
|
||||
else throwE FetchAPErrorHostMismatch
|
||||
|
||||
fetchAPIDOrH
|
||||
:: (MonadIO m, ActivityPub a, ActivityPub b)
|
||||
=> Manager
|
||||
|
@ -716,17 +743,7 @@ fetchAPIDOrH
|
|||
-> Text
|
||||
-> LocalURI
|
||||
-> ExceptT String m (Either a b)
|
||||
fetchAPIDOrH m getId h lu = do
|
||||
e <- fetchAP m $ l2f h lu
|
||||
case e of
|
||||
Left' (Doc h' x) ->
|
||||
if h == h' && getId x == lu
|
||||
then return $ Left x
|
||||
else throwE "Object @id doesn't match the URI we fetched"
|
||||
Right' (Doc h' y) ->
|
||||
if h == h'
|
||||
then return $ Right y
|
||||
else throwE "Object @id URI's host doesn't match the URI we fetched"
|
||||
fetchAPIDOrH m getId h lu = withExceptT show $ fetchAPIDOrH' m getId h lu
|
||||
|
||||
-- | Fetches the given actor and checks whether it lists the given key (as a
|
||||
-- URI, not as an embedded object). If it does, returns 'Right' the fetched
|
||||
|
|
Loading…
Reference in a new issue