Skip to content

Commit

Permalink
return 404 when the payload batch limit is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
larskuhtz authored and chessai committed Aug 26, 2024
1 parent e8b2567 commit 23726e1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Chainweb/Payload/RestAPI/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ payloadHandler db k mh = liftIO (lookupPayloadDataWithHeight db mh k) >>= \case
[ "reason" .= ("key not found" :: String)
, "key" .= k
]
Just e -> return e
Just e -> return e

-- -------------------------------------------------------------------------- --
-- POST Payload Batch Handler
Expand All @@ -89,8 +89,9 @@ payloadBatchHandler
-> PayloadDb tbl
-> BatchBody
-> Handler PayloadDataList
payloadBatchHandler batchLimit db ks
= liftIO (PayloadDataList . catMaybes <$> lookupPayloadDataWithHeightBatch db ks')
payloadBatchHandler 0 _ _ = throwError $ err404Msg @String "payload batch limit is 0"
payloadBatchHandler batchLimit db ks =
liftIO (PayloadDataList . catMaybes <$> lookupPayloadDataWithHeightBatch db ks')
where
limit = take (int batchLimit)
ks' | WithoutHeights xs <- ks = limit (fmap (Nothing,) xs)
Expand Down Expand Up @@ -123,14 +124,14 @@ outputsBatchHandler
-> PayloadDb tbl
-> BatchBody
-> Handler PayloadWithOutputsList
outputsBatchHandler batchLimit db ks
= liftIO (PayloadWithOutputsList . catMaybes <$> lookupPayloadWithHeightBatch db ks')
outputsBatchHandler 0 _ _ = throwError $ err404Msg @String "payload batch limit is 0"
outputsBatchHandler batchLimit db ks =
liftIO (PayloadWithOutputsList . catMaybes <$> lookupPayloadWithHeightBatch db ks')
where
limit = take (int batchLimit)
ks' | WithoutHeights xs <- ks = limit (fmap (Nothing,) xs)
| WithHeights xs <- ks = limit (fmap (over _1 Just) xs)


-- -------------------------------------------------------------------------- --
-- Payload API Server

Expand Down

0 comments on commit 23726e1

Please sign in to comment.