refactor: Sort error types

Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
This commit is contained in:
Wolfgang Walther
2022-01-28 19:26:33 +01:00
committed by Wolfgang Walther
parent 927ff6f1e5
commit 8980b09419
3 changed files with 54 additions and 49 deletions
+28 -28
View File
@@ -55,20 +55,20 @@ class (JSON.ToJSON a) => PgrstError a where
errorResponseFor err = responseLBS (status err) (headers err) $ errorPayload err errorResponseFor err = responseLBS (status err) (headers err) $ errorPayload err
instance PgrstError ApiRequestError where instance PgrstError ApiRequestError where
status InvalidRange = HTTP.status416
status InvalidFilters = HTTP.status405
status (InvalidBody _) = HTTP.status400
status UnsupportedVerb = HTTP.status405
status ActionInappropriate = HTTP.status405 status ActionInappropriate = HTTP.status405
status (ParseRequestError _ _) = HTTP.status400
status (QueryParamError _) = HTTP.status400
status NoRelBetween{} = HTTP.status400
status AmbiguousRelBetween{} = HTTP.status300 status AmbiguousRelBetween{} = HTTP.status300
status (AmbiguousRpc _) = HTTP.status300 status AmbiguousRpc{} = HTTP.status300
status ContentTypeError{} = HTTP.status415
status InvalidBody{} = HTTP.status400
status InvalidFilters = HTTP.status405
status InvalidRange = HTTP.status416
status NoRelBetween{} = HTTP.status400
status NoRpc{} = HTTP.status404 status NoRpc{} = HTTP.status404
status (UnacceptableSchema _) = HTTP.status406 status NotEmbedded{} = HTTP.status400
status (ContentTypeError _) = HTTP.status415 status ParseRequestError{} = HTTP.status400
status (NotEmbedded _) = HTTP.status400 status QueryParamError{} = HTTP.status400
status UnacceptableSchema{} = HTTP.status406
status UnsupportedVerb = HTTP.status405
headers _ = [ContentType.toHeader CTApplicationJSON] headers _ = [ContentType.toHeader CTApplicationJSON]
@@ -270,40 +270,40 @@ checkIsFatal _ = Nothing
data Error data Error
= GucHeadersError = ApiRequestError ApiRequestError
| GucStatusError
| BinaryFieldError ContentType | BinaryFieldError ContentType
| GucHeadersError
| GucStatusError
| JwtTokenInvalid Text
| JwtTokenMissing
| JwtTokenRequired
| NoSchemaCacheError | NoSchemaCacheError
| NotFound
| PgErr PgError
| PutMatchingPkError | PutMatchingPkError
| PutRangeNotAllowedError | PutRangeNotAllowedError
| JwtTokenMissing
| JwtTokenInvalid Text
| JwtTokenRequired
| SingularityError Integer | SingularityError Integer
| NotFound
| ApiRequestError ApiRequestError
| PgErr PgError
instance PgrstError Error where instance PgrstError Error where
status (ApiRequestError err) = status err
status BinaryFieldError{} = HTTP.status406
status GucHeadersError = HTTP.status500 status GucHeadersError = HTTP.status500
status GucStatusError = HTTP.status500 status GucStatusError = HTTP.status500
status (BinaryFieldError _) = HTTP.status406 status JwtTokenInvalid{} = HTTP.unauthorized401
status NoSchemaCacheError = HTTP.status503
status PutMatchingPkError = HTTP.status400
status PutRangeNotAllowedError = HTTP.status400
status JwtTokenMissing = HTTP.status500 status JwtTokenMissing = HTTP.status500
status (JwtTokenInvalid _) = HTTP.unauthorized401
status JwtTokenRequired = HTTP.unauthorized401 status JwtTokenRequired = HTTP.unauthorized401
status (SingularityError _) = HTTP.status406 status NoSchemaCacheError = HTTP.status503
status NotFound = HTTP.status404 status NotFound = HTTP.status404
status (PgErr err) = status err status (PgErr err) = status err
status (ApiRequestError err) = status err status PutMatchingPkError = HTTP.status400
status PutRangeNotAllowedError = HTTP.status400
status SingularityError{} = HTTP.status406
headers (SingularityError _) = [ContentType.toHeader CTSingularJSON] headers (ApiRequestError err) = headers err
headers (JwtTokenInvalid m) = [ContentType.toHeader CTApplicationJSON, invalidTokenHeader m] headers (JwtTokenInvalid m) = [ContentType.toHeader CTApplicationJSON, invalidTokenHeader m]
headers JwtTokenRequired = [ContentType.toHeader CTApplicationJSON, requiredTokenHeader] headers JwtTokenRequired = [ContentType.toHeader CTApplicationJSON, requiredTokenHeader]
headers (PgErr err) = headers err headers (PgErr err) = headers err
headers (ApiRequestError err) = headers err headers SingularityError{} = [ContentType.toHeader CTSingularJSON]
headers _ = [ContentType.toHeader CTApplicationJSON] headers _ = [ContentType.toHeader CTApplicationJSON]
instance JSON.ToJSON Error where instance JSON.ToJSON Error where
+9 -4
View File
@@ -83,10 +83,15 @@ data Payload
data InvokeMethod = InvHead | InvGet | InvPost deriving Eq data InvokeMethod = InvHead | InvGet | InvPost deriving Eq
-- | Types of things a user wants to do to tables/views/procs -- | Types of things a user wants to do to tables/views/procs
data Action = ActionCreate | ActionRead{isHead :: Bool} data Action
| ActionUpdate | ActionDelete = ActionCreate
| ActionSingleUpsert | ActionInvoke InvokeMethod | ActionRead {isHead :: Bool}
| ActionInfo | ActionInspect{isHead :: Bool} | ActionUpdate
| ActionDelete
| ActionSingleUpsert
| ActionInvoke InvokeMethod
| ActionInfo
| ActionInspect {isHead :: Bool}
deriving Eq deriving Eq
-- | The path info that will be mapped to a target (used to handle validations and errors before defining the Target) -- | The path info that will be mapped to a target (used to handle validations and errors before defining the Target)
data Path data Path
+9 -9
View File
@@ -59,19 +59,19 @@ import Protolude
data ApiRequestError data ApiRequestError
= ActionInappropriate = ActionInappropriate
| InvalidRange
| InvalidBody ByteString
| ParseRequestError Text Text
| QueryParamError QPError
| NoRelBetween Text Text Text
| AmbiguousRelBetween Text Text [Relationship] | AmbiguousRelBetween Text Text [Relationship]
| AmbiguousRpc [ProcDescription] | AmbiguousRpc [ProcDescription]
| NoRpc Text Text [Text] Bool ContentType Bool
| InvalidFilters
| UnacceptableSchema [Text]
| ContentTypeError [ByteString] | ContentTypeError [ByteString]
| UnsupportedVerb -- Unreachable? | InvalidBody ByteString
| InvalidFilters
| InvalidRange
| NoRelBetween Text Text Text
| NoRpc Text Text [Text] Bool ContentType Bool
| NotEmbedded Text | NotEmbedded Text
| ParseRequestError Text Text
| QueryParamError QPError
| UnacceptableSchema [Text]
| UnsupportedVerb -- Unreachable?
data QPError = QPError Text Text data QPError = QPError Text Text