2016-11-24 4 views
0

내가 시도한 다음yesod를 사용하면 어떻게 사용자 정의 HTTP 상태 코드로 defaultLayout을 보낼 수 있습니까?

sendResponseStatus status403 $ (defaultLayout [whamlet|Foo|] :: Handler Html) 
나에게 이러한 유형의 오류가 있습니다

:

<interactive>:1:1: Warning: 
    Could not deduce (ToTypedContent (Handler Html)) 
     arising from a use of ‘sendResponseStatus’ 
    from the context (MonadHandler m) 
     bound by the inferred type of it :: MonadHandler m => m a 
     at <interactive>:1:1 
    In the expression: sendResponseStatus status403 
    In the expression: 
     sendResponseStatus status403 
     $ (defaultLayout 
      ((asWidgetT . toWidget) 
       ((blaze-markup-0.7.0.3:Text.Blaze.Internal.preEscapedText 
       . Data.Text.pack) 
       "Foo")) :: 
      Handler Html) 

답변

2

그것은 밝혀 sendResponseStatusHandler Html 기대되지 않는다는 것을, 그러나 일반 Html 대신 작동합니다

html <- defaultLayout [whamlet|Foo|] 
sendResponseStatus status403 html 

나를 컴파일하고 예상대로 실행합니다.

또한 같은이 로직을 캡슐화하는 의미가 있습니다하십시오 Handler에 통과 할 수있는 것은 나에게 아주 조금 더 강력한 것 같습니다

sendResponseStatusHandler :: (ToTypedContent c, MonadHandler m) => Status -> m c -> m b 
sendResponseStatusHandler status handler = do 
    response <- handler 
    sendResponseStatus status response 

입니다.