From f56efeb039783dbfcf546c4d3ca95833657f6988 Mon Sep 17 00:00:00 2001 From: Diogo Biazus Date: Sun, 18 Oct 2015 20:02:33 -0400 Subject: [PATCH] Reduces conde duplication assimbling response vody for RPC --- src/PostgREST/App.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs index 18248ddff..bcd0627e1 100644 --- a/src/PostgREST/App.hs +++ b/src/PostgREST/App.hs @@ -176,9 +176,10 @@ app dbstructure conf reqBody req = asJson (callProc qi $ fromMaybe M.empty (decode reqBody)) bodyJson :: Maybe (Identity Value) <- H.maybeEx call return $ responseLBS status200 [jsonH] - (if hasPrefer "return=jwt" - then ("{\"token\":\"" <> (cs $ tokenJWT jwtSecret $ fromMaybe "[]" $ runIdentity <$> bodyJson) <> "\"}") - else (cs $ encode $ fromMaybe emptyArray $ runIdentity <$> bodyJson)) + (let body = fromMaybe emptyArray $ runIdentity <$> bodyJson in + if hasPrefer "return=jwt" + then ("{\"token\":\"" <> (cs $ tokenJWT jwtSecret $ body) <> "\"}") + else (cs $ encode $ body)) else return $ responseLBS status404 [] "" -- check that proc exists