Provide more context about unknown routes

This commit is contained in:
Joe Nelson
2015-11-18 23:51:59 -08:00
parent b260cff6fd
commit 8f04967103
+8 -7
View File
@@ -27,6 +27,7 @@ data Action = ActionCreate | ActionRead
-- | The target db object of a user action -- | The target db object of a user action
data Target = TargetIdent QualifiedIdentifier data Target = TargetIdent QualifiedIdentifier
| TargetRoot | TargetRoot
| TargetUnknown [T.Text]
-- | Enumeration of currently supported content types for -- | Enumeration of currently supported content types for
-- route responses and upload payloads -- route responses and upload payloads
data ContentType = ApplicationJSON | TextCSV data ContentType = ApplicationJSON | TextCSV
@@ -47,7 +48,7 @@ data Intent = Intent {
-- | Set to Nothing for malformed range -- | Set to Nothing for malformed range
, iRange :: Maybe NonnegRange , iRange :: Maybe NonnegRange
-- | Set to Nothing for strangely nested urls -- | Set to Nothing for strangely nested urls
, iTarget :: Maybe Target , iTarget :: Target
-- | The content type the client most desires (or JSON if undecided) -- | The content type the client most desires (or JSON if undecided)
, iAccepts :: Either BS.ByteString ContentType , iAccepts :: Either BS.ByteString ContentType
-- | Data sent by client and used for mutation actions -- | Data sent by client and used for mutation actions
@@ -73,12 +74,12 @@ userIntent schema req reqBody =
"OPTIONS" -> ActionInfo "OPTIONS" -> ActionInfo
other -> ActionUnknown other other -> ActionUnknown other
target = case path of target = case path of
[] -> Just TargetRoot [] -> TargetRoot
[table] -> Just $ TargetIdent [table] -> TargetIdent
$ QualifiedIdentifier schema table $ QualifiedIdentifier schema table
["rpc", proc] -> Just $ TargetIdent ["rpc", proc] -> TargetIdent
$ QualifiedIdentifier schema proc $ QualifiedIdentifier schema proc
_ -> Nothing other -> TargetUnknown other
reqPayload = case pickContentType (lookupHeader "content-type") of reqPayload = case pickContentType (lookupHeader "content-type") of
Right ApplicationJSON -> Right ApplicationJSON ->
either (PayloadParseError . cs) either (PayloadParseError . cs)