Fix embeded relations error message (#767)
This commit is contained in:
@@ -315,10 +315,6 @@ contentRangeH lower upper total =
|
||||
totalNotZero = fromMaybe True ((/=) 0 <$> total)
|
||||
fromInRange = lower <= upper
|
||||
|
||||
formatRelationError :: Text -> Text
|
||||
formatRelationError = formatGeneralError
|
||||
"could not find foreign keys between these entities"
|
||||
|
||||
formatParserError :: ParseError -> Text
|
||||
formatParserError e = formatGeneralError message details
|
||||
where
|
||||
@@ -327,14 +323,15 @@ formatParserError e = formatGeneralError message details
|
||||
$ showErrorMessages "or" "unknown parse error" "expecting" "unexpected" "end of input" (errorMessages e)
|
||||
|
||||
formatGeneralError :: Text -> Text -> Text
|
||||
formatGeneralError message details = toS $ encode $ object [
|
||||
"message" .= message,
|
||||
"details" .= details]
|
||||
formatGeneralError message details = message <> ", " <> details
|
||||
|
||||
augumentRequestWithJoin :: Schema -> [Relation] -> ReadRequest -> Either Text ReadRequest
|
||||
augumentRequestWithJoin schema allRels request =
|
||||
(first formatRelationError . addRelations schema allRels Nothing) request
|
||||
>>= addJoinConditions schema
|
||||
where
|
||||
formatRelationError = formatGeneralError
|
||||
"could not find foreign keys between these entities"
|
||||
|
||||
addFiltersOrdersRanges :: ApiRequest -> Either ParseError (ReadRequest -> ReadRequest)
|
||||
addFiltersOrdersRanges apiRequest = foldr1 (liftA2 (.)) [
|
||||
|
||||
@@ -7,7 +7,6 @@ module PostgREST.Error (apiRequestErrResponse, pgErrResponse, errResponse, prett
|
||||
import Protolude
|
||||
import Data.Aeson ((.=))
|
||||
import qualified Data.Aeson as JSON
|
||||
import qualified Data.Text as T
|
||||
import qualified Hasql.Pool as P
|
||||
import qualified Hasql.Session as H
|
||||
import qualified Network.HTTP.Types.Status as HT
|
||||
@@ -22,9 +21,10 @@ apiRequestErrResponse err =
|
||||
ErrorInvalidRange -> errResponse HT.status416 "HTTP Range error"
|
||||
|
||||
errResponse :: HT.Status -> Text -> Response
|
||||
errResponse status message = responseLBS status
|
||||
[toHeader CTApplicationJSON]
|
||||
(toS $ T.concat ["{\"message\":\"",message,"\"}"])
|
||||
errResponse status message = jsonErrResponse status $ JSON.object ["message" .= message]
|
||||
|
||||
jsonErrResponse :: HT.Status -> JSON.Value -> Response
|
||||
jsonErrResponse status message = responseLBS status [toHeader CTApplicationJSON] $ JSON.encode message
|
||||
|
||||
pgErrResponse :: Bool -> P.UsageError -> Response
|
||||
pgErrResponse authed e =
|
||||
|
||||
Reference in New Issue
Block a user