messages: better error for related order
This commit is contained in:
committed by
Steve Chavez
parent
2aa0e091bb
commit
cca0b5ae66
@@ -71,13 +71,13 @@ data ApiRequestError
|
|||||||
| InvalidRpcMethod ByteString
|
| InvalidRpcMethod ByteString
|
||||||
| LimitNoOrderError
|
| LimitNoOrderError
|
||||||
| NotFound
|
| NotFound
|
||||||
| NotToOne Text Text
|
|
||||||
| NoRelBetween Text Text Text
|
| NoRelBetween Text Text Text
|
||||||
| NoRpc Text Text [Text] Bool MediaType Bool
|
| NoRpc Text Text [Text] Bool MediaType Bool
|
||||||
| NotEmbedded Text
|
| NotEmbedded Text
|
||||||
| ParseRequestError Text Text
|
| ParseRequestError Text Text
|
||||||
| PutRangeNotAllowedError
|
| PutRangeNotAllowedError
|
||||||
| QueryParamError QPError
|
| QueryParamError QPError
|
||||||
|
| RelatedOrderNotToOne Text Text
|
||||||
| SpreadNotToOne Text Text
|
| SpreadNotToOne Text Text
|
||||||
| UnacceptableSchema [Text]
|
| UnacceptableSchema [Text]
|
||||||
| UnsupportedMethod ByteString
|
| UnsupportedMethod ByteString
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ instance PgrstError ApiRequestError where
|
|||||||
status InvalidRpcMethod{} = HTTP.status405
|
status InvalidRpcMethod{} = HTTP.status405
|
||||||
status InvalidRange{} = HTTP.status416
|
status InvalidRange{} = HTTP.status416
|
||||||
status NotFound = HTTP.status404
|
status NotFound = HTTP.status404
|
||||||
status NotToOne{} = HTTP.status400
|
|
||||||
|
|
||||||
status NoRelBetween{} = HTTP.status400
|
status NoRelBetween{} = HTTP.status400
|
||||||
status NoRpc{} = HTTP.status404
|
status NoRpc{} = HTTP.status404
|
||||||
@@ -72,6 +71,7 @@ instance PgrstError ApiRequestError where
|
|||||||
status ParseRequestError{} = HTTP.status400
|
status ParseRequestError{} = HTTP.status400
|
||||||
status PutRangeNotAllowedError = HTTP.status400
|
status PutRangeNotAllowedError = HTTP.status400
|
||||||
status QueryParamError{} = HTTP.status400
|
status QueryParamError{} = HTTP.status400
|
||||||
|
status RelatedOrderNotToOne{} = HTTP.status400
|
||||||
status SpreadNotToOne{} = HTTP.status400
|
status SpreadNotToOne{} = HTTP.status400
|
||||||
status UnacceptableSchema{} = HTTP.status406
|
status UnacceptableSchema{} = HTTP.status406
|
||||||
status UnsupportedMethod{} = HTTP.status405
|
status UnsupportedMethod{} = HTTP.status405
|
||||||
@@ -154,10 +154,10 @@ instance JSON.ToJSON ApiRequestError where
|
|||||||
"details" .= JSON.Null,
|
"details" .= JSON.Null,
|
||||||
"hint" .= JSON.Null]
|
"hint" .= JSON.Null]
|
||||||
|
|
||||||
toJSON (NotToOne origin target) = JSON.object [
|
toJSON (RelatedOrderNotToOne origin target) = JSON.object [
|
||||||
"code" .= ApiRequestErrorCode18,
|
"code" .= ApiRequestErrorCode18,
|
||||||
"message" .= ("'" <> origin <> "' and '" <> target <> "' do not form a many-to-one or one-to-one relationship" :: Text),
|
"message" .= ("A related order on '" <> target <> "' is not possible" :: Text),
|
||||||
"details" .= JSON.Null,
|
"details" .= ("'" <> origin <> "' and '" <> target <> "' do not form a many-to-one or one-to-one relationship" :: Text),
|
||||||
"hint" .= JSON.Null]
|
"hint" .= JSON.Null]
|
||||||
|
|
||||||
toJSON (SpreadNotToOne origin target) = JSON.object [
|
toJSON (SpreadNotToOne origin target) = JSON.object [
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ addRelatedOrders (Node rp@ReadPlan{order,from} forest) = do
|
|||||||
name = fromMaybe relName relAlias in
|
name = fromMaybe relName relAlias in
|
||||||
if isToOne == Just True
|
if isToOne == Just True
|
||||||
then Right $ ot{otRelation=relAggAlias}
|
then Right $ ot{otRelation=relAggAlias}
|
||||||
else Left $ NotToOne (qiName from) name
|
else Left $ RelatedOrderNotToOne (qiName from) name
|
||||||
Nothing ->
|
Nothing ->
|
||||||
Left $ NotEmbedded otRelation
|
Left $ NotEmbedded otRelation
|
||||||
|
|
||||||
|
|||||||
@@ -107,17 +107,32 @@ spec =
|
|||||||
|
|
||||||
it "fails when is not a to-one relationship" $ do
|
it "fails when is not a to-one relationship" $ do
|
||||||
get "/clients?select=*,projects(*)&order=projects(id)" `shouldRespondWith`
|
get "/clients?select=*,projects(*)&order=projects(id)" `shouldRespondWith`
|
||||||
[json|{"code":"PGRST118","details":null,"hint":null,"message":"'clients' and 'projects' do not form a many-to-one or one-to-one relationship"}|]
|
[json|{
|
||||||
|
"code":"PGRST118",
|
||||||
|
"details":"'clients' and 'projects' do not form a many-to-one or one-to-one relationship",
|
||||||
|
"hint":null,
|
||||||
|
"message":"A related order on 'projects' is not possible"
|
||||||
|
}|]
|
||||||
{ matchStatus = 400
|
{ matchStatus = 400
|
||||||
, matchHeaders = [matchContentTypeJson]
|
, matchHeaders = [matchContentTypeJson]
|
||||||
}
|
}
|
||||||
get "/clients?select=*,pros:projects(*)&order=pros(id)" `shouldRespondWith`
|
get "/clients?select=*,pros:projects(*)&order=pros(id)" `shouldRespondWith`
|
||||||
[json|{"code":"PGRST118","details":null,"hint":null,"message":"'clients' and 'pros' do not form a many-to-one or one-to-one relationship"}|]
|
[json|{
|
||||||
|
"code":"PGRST118",
|
||||||
|
"details":"'clients' and 'pros' do not form a many-to-one or one-to-one relationship",
|
||||||
|
"hint":null,
|
||||||
|
"message":"A related order on 'pros' is not possible"
|
||||||
|
}|]
|
||||||
{ matchStatus = 400
|
{ matchStatus = 400
|
||||||
, matchHeaders = [matchContentTypeJson]
|
, matchHeaders = [matchContentTypeJson]
|
||||||
}
|
}
|
||||||
get "/designers?select=id,computed_videogames(id)&order=computed_videogames(id).desc" `shouldRespondWith`
|
get "/designers?select=id,computed_videogames(id)&order=computed_videogames(id).desc" `shouldRespondWith`
|
||||||
[json|{"code":"PGRST118","details":null,"hint":null,"message":"'designers' and 'computed_videogames' do not form a many-to-one or one-to-one relationship"}|]
|
[json|{
|
||||||
|
"code":"PGRST118",
|
||||||
|
"details":"'designers' and 'computed_videogames' do not form a many-to-one or one-to-one relationship",
|
||||||
|
"hint":null,
|
||||||
|
"message":"A related order on 'computed_videogames' is not possible"
|
||||||
|
}|]
|
||||||
{ matchStatus = 400
|
{ matchStatus = 400
|
||||||
, matchHeaders = [matchContentTypeJson]
|
, matchHeaders = [matchContentTypeJson]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user