我想在Servant中执行删除操作并返回错误或()。这是我的代码:
del :: Int -> ExceptT ServantErr IO ()
del myId = liftIO $ do
cn <- getConnection
a <- execute cn "delete from table1 where id = ?" [myId]
case a of
1 -> return ()
_ -> throwE err503 --compile error
错误是:
Couldn't match expected type ‘IO ()’
with actual type ‘ExceptT ServantErr m0 a0’
In the expression: throwE err503
In a case alternative: _ -> throwE err503
如果可能的话,我不希望在每个表达式之前使用 liftIO :
del myId = do
cn <- liftIO getConnection
a <- liftIO $ execute cn "delete from table1 where id = ?" [myId]
case a of
1 -> return ()
_ -> throwE err503
那我该如何返回错误呢?