2017-05-02 11 views
0

내가했을 때 : Yesod Handler 내에서 예외를 어떻게 catch 할 수 있습니까?

foos <- (return $ map (encode .> cs .> jsonToFoo body) `catch` r400 

나는 다음과 같은 유형의 오류가 발생했습니다 :

/path/to/File.hs:47:78: error: 
    • Couldn't match type ‘(->) e0’ with ‘IO’ 
     arising from a functional dependency between: 
      constraint ‘MonadBase IO ((->) e0)’ arising from a use of ‘r400’ 
      instance ‘MonadBase ((->) r) ((->) r)’ at <no location info> 
    • In the second argument of ‘catch’, namely ‘r400’ 
     In a stmt of a 'do' block: 
     foos <- (return $ map (encode .> cs .> jsonToFoo) body) 
       `catch` r400 
     In the expression: 
     do { (body :: [Value]) <- requireJsonBody; 
      foos <- (return $ map (encode .> cs .> jsonToFoo) body) 
        `catch` r400; 
      .... } 

수있는 방법이 있다면, 그것은 liftIO 그것은하지 않습니다 포함?

+0

[리프팅베이스 패키지 catch''버전]을 사용하여 시도 (https://hackage.haskell.org/package/lifted-base-0.2.3.10/docs/Control-Exception-Lifted.html# v : catch). –

+0

@AlexisKing 감사합니다. – Wizek

+0

@AlexisKing 나는 동일한 유형의 오류 : '형식과 일치 할 수 없습니다 -'IO'' – Wizek

답변

2

난 그냥 catch에 대한 인수 누락되었습니다

foos <- (return $ map (encode .> cs .> jsonToFoo body) 
    `catch` (\(e :: SomeException) -> r400) 

너무 나쁜 그것은 유형의 오류를하지 더 분명 나를 위해이었다.