feat: improve error details of PGRST301 error

This commit is contained in:
Taimoor Zaeem
2025-09-14 13:37:17 -05:00
committed by Steve Chavez
parent 75972e9ffe
commit a8f40c4908
4 changed files with 18 additions and 6 deletions
+2 -2
View File
@@ -76,8 +76,8 @@ parseToken AppConfig{..} (Just tkn) time = do
-- BadAlgorithm
-- KeyError
-- BadCrypto
jwtDecodeError (JWT.KeyError _) = JwtDecodeErr KeyError
jwtDecodeError (JWT.BadAlgorithm _) = JwtDecodeErr BadAlgorithm
jwtDecodeError (JWT.KeyError m) = JwtDecodeErr $ KeyError m
jwtDecodeError (JWT.BadAlgorithm m) = JwtDecodeErr $ BadAlgorithm m
jwtDecodeError JWT.BadCrypto = JwtDecodeErr BadCrypto
-- Control never reaches here, the decode function only returns the above three
jwtDecodeError _ = JwtDecodeErr UnreachableDecodeError
+8 -4
View File
@@ -659,8 +659,8 @@ data JwtError
data JwtDecodeError
= EmptyAuthHeader
| UnexpectedParts Int
| KeyError
| BadAlgorithm
| KeyError Text
| BadAlgorithm Text
| BadCrypto
| UnsupportedTokenType
| UnreachableDecodeError
@@ -745,8 +745,8 @@ instance ErrorBody JwtError where
message (JwtDecodeErr e) = case e of
EmptyAuthHeader -> "Empty JWT is sent in Authorization header"
UnexpectedParts n -> "Expected 3 parts in JWT; got " <> show n
KeyError -> "No suitable key or wrong key type"
BadAlgorithm -> "Wrong or unsupported encoding algorithm"
KeyError _ -> "No suitable key or wrong key type"
BadAlgorithm _ -> "Wrong or unsupported encoding algorithm"
BadCrypto -> "JWT cryptographic operation failed"
UnsupportedTokenType -> "Unsupported token type"
UnreachableDecodeError -> "JWT couldn't be decoded"
@@ -762,6 +762,10 @@ instance ErrorBody JwtError where
IatClaimNotNumber -> "The JWT 'iat' claim must be a number"
AudClaimNotStringOrArray -> "The JWT 'aud' claim must be a string or an array of strings"
details (JwtDecodeErr jde) = case jde of
KeyError dets -> Just $ JSON.String dets
BadAlgorithm dets -> Just $ JSON.String dets
_ -> Nothing
details _ = Nothing
hint _ = Nothing