Skip to content

Commit 5ca5bbd

Browse files
committed
fix(#1841): fix unhandled missing index exception
1 parent 31a3821 commit 5ca5bbd

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ changes.
1717
### Fixed
1818

1919
- Fix displaying DRep with doNotList property as string
20+
- Handle exception when no index is provided to /proposal/get endpoint [Issue 1841](https://github.com/IntersectMBO/govtool/issues/1841)
2021

2122
### Changed
2223

govtool/backend/src/VVA/API/Types.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,14 @@ instance ToJSON GovActionId where
139139
instance FromHttpApiData GovActionId where
140140
parseUrlPiece t = case Text.splitOn "#" t of
141141
[hash, rest] -> do
142-
index <- case readMaybe $ Text.unpack rest of
143-
Just x -> pure x
144-
_ -> Left (Text.tail rest <> " is not a number")
145-
hexHash <- parseUrlPiece hash
146-
Right $ GovActionId hexHash index
142+
if Text.null rest
143+
then Left "Missing index in hash#index format"
144+
else do
145+
index <- case readMaybe $ Text.unpack rest of
146+
Just x -> pure x
147+
_ -> Left (rest <> " is not a number")
148+
hexHash <- parseUrlPiece hash
149+
Right $ GovActionId hexHash index
147150
_ -> Left "Not a valid hash#index value"
148151

149152
exampleGovActionId :: Text

0 commit comments

Comments
 (0)