Rig-6ren">
gpt4 book ai didi

amazon-web-services - 使用 Lenses 捕获多个异常

转载 作者:行者123 更新时间:2023-12-04 13:32:26 24 4
gpt4 key购买 nike

我正在使用 LensAmazonka 来处理错误,但我很难处理错误:

doSignup e p = (AWS.send $ AWS.signUp "secret" e p)
$> Right ()
& catching_ AWS._UsernameExistsException (return $ Left AlreadyExistingEmail)
& catching_ AWS._InvalidPasswordException (return $ Left WeakPassword)
& catching AWS._SertviceError (return . UnknownSignUpError)

data SignUpError where
AlreadyExistingEmail :: SignUpError
NotAnEmail :: SignUpError
WeakPassword :: SignUpError
UnknownSignUpError :: forall a. Show a => a -> SignUpError

我努力保持一致的捕获行为,当抛出 _UsernameExistsException 时,我得到了一个 Left WeakPassword

它变得更奇怪了,因为它在我删除 WeakPassword 行时起作用。

虽然我得到正确的错误(只保留最后一行):

       expected: Right ()
but got: Left UnknownSignUpError ServiceError' {_serviceAbbrev = Abbrev "CognitoIdentityProvider", _serviceStatus = Status {statusCode = 400, statusMessage = "Bad Request"}, _serviceHeaders = [("Date","Tue, 06 Oct 2020 05:38:56 GMT"),("Content-Type","application/x-amz-json-1.1"),("Content-Length","96"),("Connection","keep-alive"),("x-amzn-RequestId","b09210a3-41ed-46ee-af4f-46db58b98695"),("x-amzn-ErrorType","UsernameExistsException:"),("x-amzn-ErrorMessage","An account with the given email already exists.")], _serviceCode = ErrorCode "UsernameExists", _serviceMessage = Just (ErrorMessage "An account with the given email already exists."), _serviceRequestId = Just (RequestId "b09210a3-41ed-46ee-af4f-46db58b98695")}

我曾尝试使用 catches,但 handler 需要 Typeable 镜头,但事实并非如此。

我怎样才能有一种“类似模式匹配”的方式来处理异常?提前致谢。

最佳答案

事实上 Control.Lens.catching 被用来代替 Network.AWS.Prelude.catching ,后者搞乱了异常处理。

关于amazon-web-services - 使用 Lenses 捕获多个异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64211729/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com