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 Nothing = "Object @id doesn't match the URI we fetched"
|
||||||
showError (Just e) = displayException e
|
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
|
fetchAPIDOrH
|
||||||
:: (MonadIO m, ActivityPub a, ActivityPub b)
|
:: (MonadIO m, ActivityPub a, ActivityPub b)
|
||||||
=> Manager
|
=> Manager
|
||||||
|
@ -716,17 +743,7 @@ fetchAPIDOrH
|
||||||
-> Text
|
-> Text
|
||||||
-> LocalURI
|
-> LocalURI
|
||||||
-> ExceptT String m (Either a b)
|
-> ExceptT String m (Either a b)
|
||||||
fetchAPIDOrH m getId h lu = do
|
fetchAPIDOrH m getId h lu = withExceptT show $ fetchAPIDOrH' m getId h lu
|
||||||
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"
|
|
||||||
|
|
||||||
-- | Fetches the given actor and checks whether it lists the given key (as a
|
-- | 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
|
-- URI, not as an embedded object). If it does, returns 'Right' the fetched
|
||||||
|
|
Loading…
Reference in a new issue