diff --git a/Web/Scotty.hs b/Web/Scotty.hs index 7c6b81b3..c5c6829f 100644 --- a/Web/Scotty.hs +++ b/Web/Scotty.hs @@ -116,12 +116,14 @@ setMaxRequestBodySize = Trans.setMaxRequestBodySize -- Uncaught exceptions turn into HTTP 500 responses. raise :: Text -> ActionM a raise = Trans.raise +{-# DEPRECATED raise "Throw an exception instead" #-} -- | Throw a 'StatusError' exception that has an associated HTTP error code and can be caught with 'catch'. -- -- Uncaught exceptions turn into HTTP responses corresponding to the given status. raiseStatus :: Status -> Text -> ActionM a raiseStatus = Trans.raiseStatus +{-# DEPRECATED raiseStatus "Use status, text, and finish instead" #-} -- | Throw an exception which can be caught within the scope of the current Action with 'catch'. -- diff --git a/Web/Scotty/Action.hs b/Web/Scotty/Action.hs index 3d576b03..54a12a3d 100644 --- a/Web/Scotty/Action.hs +++ b/Web/Scotty/Action.hs @@ -180,12 +180,14 @@ raise :: (MonadIO m) => T.Text -- ^ Error text -> ActionT m a raise = raiseStatus status500 +{-# DEPRECATED raise "Throw an exception instead" #-} -- | Throw a 'StatusError' exception that has an associated HTTP error code and can be caught with 'catch'. -- -- Uncaught exceptions turn into HTTP responses corresponding to the given status. raiseStatus :: Monad m => Status -> T.Text -> ActionT m a raiseStatus s = E.throw . StatusError s +{-# DEPRECATED raiseStatus "Use status, text, and finish instead" #-} -- | Throw an exception which can be caught within the scope of the current Action with 'catch'. -- diff --git a/Web/Scotty/Internal/Types.hs b/Web/Scotty/Internal/Types.hs index 38fab71d..4de097c4 100644 --- a/Web/Scotty/Internal/Types.hs +++ b/Web/Scotty/Internal/Types.hs @@ -142,6 +142,7 @@ tryNext io = catch (io >> pure True) $ \e -> -- | E.g. when a parameter is not found in a query string (400 Bad Request) or when parsing a JSON body fails (422 Unprocessable Entity) data StatusError = StatusError Status Text deriving (Show, Typeable) instance E.Exception StatusError +{-# DEPRECATED StatusError "If it is supposed to be caught, a proper exception type should be defined" #-} -- | Specializes a 'Handler' to the 'ActionT' monad type ErrorHandler m = Handler (ActionT m) () diff --git a/Web/Scotty/Trans/Lazy.hs b/Web/Scotty/Trans/Lazy.hs index 0f6fb334..484cbbcc 100644 --- a/Web/Scotty/Trans/Lazy.hs +++ b/Web/Scotty/Trans/Lazy.hs @@ -17,12 +17,14 @@ raise :: (MonadIO m) => T.Text -- ^ Error text -> ActionT m a raise = Base.raise . T.toStrict +{-# DEPRECATED raise "Throw an exception instead" #-} -- | Throw a 'StatusError' exception that has an associated HTTP error code and can be caught with 'rescue'. -- -- Uncaught exceptions turn into HTTP responses corresponding to the given status. raiseStatus :: Monad m => Status -> T.Text -> ActionT m a raiseStatus s = Base.raiseStatus s . T.toStrict +{-# DEPRECATED raiseStatus "Use status, text, and finish instead" #-} -- | Redirect to given URL. Like throwing an uncatchable exception. Any code after the call to redirect -- will not be run. diff --git a/changelog.md b/changelog.md index 35f15736..bd0c0d17 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ * renamed `captureParam`, `captureParamMaybe`, and `captureParams` to `pathParam`, `pathParamMaybe`, `pathParams` respectively, keeping the old names as their synonyms * Scotty's API such as `queryParam` now throws `ScottyException` rather than `StatusException`. Uncaught exceptions are handled by `scottyExceptionHandler`, resembling the existing behaviour +* Deprecate `StatusError`, `raise` and `raiseStatus` ## 0.20.1 [2023.10.03]