Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

withDB' simple wrapper to disregard exceptions

  • Loading branch information...
commit f9e8a9529430e57a04a95029d28f75be8a708008 1 parent 7f00b97
@ozataman authored
Showing with 11 additions and 1 deletion.
  1. +11 −1 src/Snap/Extension/MongoDB.hs
View
12 src/Snap/Extension/MongoDB.hs
@@ -37,10 +37,19 @@ import Snap.Types
class MonadSnap m => MonadMongoDB m where
----------------------------------------------------------------------------
- -- |
+ -- | Run given MongoDB action against the database
withDB :: ReaderT Database (Action m) a -> m (Either Failure a)
+ ----------------------------------------------------------------------------
+ -- | Same as 'withDB' but calls 'error' if there is an exception
+ withDB' :: ReaderT Database (Action m) a -> m a
+ withDB' run = do
+ r <- withDB run
+ either (error . show) return r
+
+
+
------------------------------------------------------------------------------
-- | Get strict ByteString to work directly with BSON auto-casting
instance Val B8.ByteString where
@@ -55,3 +64,4 @@ instance Val [Word8] where
val = val . fmap w2c
cast' x = fmap (fmap c2w) . cast' $ x
cast' _ = Nothing
+
Please sign in to comment.
Something went wrong with that request. Please try again.