From 2babde3d7870ec61e8f6f05004c8f9bb6a953cd3 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Wed, 17 Feb 2010 09:37:52 +0200 Subject: [PATCH] Removed invalidParams --- Yesod/Handler.hs | 4 +--- Yesod/Helpers/Auth.hs | 23 +++++------------------ Yesod/Request.hs | 6 ++---- Yesod/Response.hs | 2 +- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/Yesod/Handler.hs b/Yesod/Handler.hs index 6a06903c..082b461f 100644 --- a/Yesod/Handler.hs +++ b/Yesod/Handler.hs @@ -86,8 +86,6 @@ instance Exception e => Failure e (Handler yesod) where instance RequestReader (Handler yesod) where getRawRequest = Handler $ \(HandlerData rr _) -> return ([], HCContent rr) - invalidParams = invalidArgs . map helper where - helper ((_pt, pn, _pvs), e) = (pn, show e) getYesod :: Handler yesod yesod getYesod = Handler $ \(HandlerData _ yesod) -> return ([], HCContent yesod) @@ -153,7 +151,7 @@ notFound = errorResponse NotFound permissionDenied :: Handler yesod a permissionDenied = errorResponse PermissionDenied -invalidArgs :: [(ParamName, ParamValue)] -> Handler yesod a +invalidArgs :: [(ParamName, String)] -> Handler yesod a invalidArgs = errorResponse . InvalidArgs ------- Headers diff --git a/Yesod/Helpers/Auth.hs b/Yesod/Helpers/Auth.hs index fee5aa55..130ec0f3 100644 --- a/Yesod/Helpers/Auth.hs +++ b/Yesod/Helpers/Auth.hs @@ -34,7 +34,7 @@ import qualified Data.ByteString.Char8 as B8 import Data.Maybe (fromMaybe) import qualified Network.Wai import Data.Typeable (Typeable) -import Control.Exception (Exception, SomeException (..)) +import Control.Exception (Exception) class YesodApproot a => YesodAuth a where -- | The following breaks DRY, but I cannot think of a better solution @@ -91,26 +91,10 @@ instance ConvertSuccess OIDFormReq Html where convertSuccess (OIDFormReq (Just s) _) = Tag "p" [("class", "message")] $ cs s -someParam :: (Monad m, RequestReader m) - => ParamType - -> (RawRequest -> ParamName -> [ParamValue]) - -> ParamName - -> m ParamValue -someParam pt paramList pn = do - rr <- getRawRequest - case paramList rr pn of - [x] -> return x - x -> invalidParams [((pt, pn, x), SomeException ExpectedSingleParam)] - data ExpectedSingleParam = ExpectedSingleParam deriving (Show, Typeable) instance Exception ExpectedSingleParam -getParam :: (Monad m, RequestReader m) - => ParamName - -> m ParamValue -getParam = someParam GetParam getParams - authOpenidForm :: Yesod y => Handler y ChooseRep authOpenidForm = do rr <- getRawRequest @@ -134,7 +118,10 @@ authOpenidForm = do authOpenidForward :: YesodAuth y => Handler y () authOpenidForward = do - oid <- getParam "openid" + rr <- getRawRequest + oid <- case getParams rr "openid" of + [x] -> return x + _ -> invalidArgs [("openid", show ExpectedSingleParam)] authroot <- getFullAuthRoot let complete = authroot ++ "/openid/complete/" res <- runAttemptT $ OpenId.getForwardUrl oid complete diff --git a/Yesod/Request.hs b/Yesod/Request.hs index a48a3db7..1c455faa 100644 --- a/Yesod/Request.hs +++ b/Yesod/Request.hs @@ -32,7 +32,6 @@ module Yesod.Request , ParamType (..) , ParamName , ParamValue - , ParamException #if TEST , testSuite #endif @@ -47,7 +46,6 @@ import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import Data.Convertible.Text import Control.Arrow ((***)) -import Control.Exception (SomeException (..)) import Data.Maybe (fromMaybe) import "transformers" Control.Monad.Trans import Control.Concurrent.MVar @@ -61,11 +59,11 @@ import Test.Framework (testGroup, Test) data ParamType = GetParam | PostParam type ParamName = String type ParamValue = String -type ParamException = [((ParamType, ParamName, [ParamValue]), SomeException)] class RequestReader m where getRawRequest :: m RawRequest - invalidParams :: ParamException -> m a +instance RequestReader ((->) RawRequest) where + getRawRequest = id languages :: (Functor m, RequestReader m) => m [Language] languages = rawLangs `fmap` getRawRequest diff --git a/Yesod/Response.hs b/Yesod/Response.hs index 90530cfa..6c5a5726 100644 --- a/Yesod/Response.hs +++ b/Yesod/Response.hs @@ -192,7 +192,7 @@ data SpecialResponse = data ErrorResponse = NotFound | InternalError String - | InvalidArgs [(String, String)] + | InvalidArgs [(String, String)] -- FIXME use SomeException? | PermissionDenied deriving (Show, Eq)