@@ -1,8 +1,8 @@
1{-# LANGUAGE DeriveDataTypeable #-}
1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
4−-- | Module for parsing errors from posgresql error messages.
4+-- | Module for parsing errors from postgresql error messages.
5−-- Currently in only parses integrity violation errors (class 23).
5+-- Currently only parses integrity violation errors (class 23).
7-- /Note: Success of parsing may depend on language settings./
7-- /Note: Success of parsing may depend on language settings./
8----------------------------------------------------------
8----------------------------------------------------------
@@ -11,6 +11,9 @@ module Database.PostgreSQL.Simple.Errors
11 , constraintViolation
11 , constraintViolation
12 , constraintViolationE
12 , constraintViolationE
13 , catchViolation
13 , catchViolation
14+ , isSerializationError
15+ , isNoActiveTransactionError
16+ , isFailedTransactionError
@@ -106,3 +109,20 @@ parseQ2 = (,) <$> parseQ1 <*> parseQ1
107parseMaybe :: Parser a -> ByteString -> Maybe a
110parseMaybe :: Parser a -> ByteString -> Maybe a
108parseMaybe p b = either (const Nothing) Just $ parseOnly p b
111parseMaybe p b = either (const Nothing) Just $ parseOnly p b
113+------------------------------------------------------------------------
116+-- http://www.postgresql.org/docs/current/static/errcodes-appendix.html
118+isSerializationError :: SqlError -> Bool
119+isSerializationError = isSqlState "40001"
121+isNoActiveTransactionError :: SqlError -> Bool
122+isNoActiveTransactionError = isSqlState "25P01"
124+isFailedTransactionError :: SqlError -> Bool
125+isFailedTransactionError = isSqlState "25P02"
127+isSqlState :: ByteString -> SqlError -> Bool
128+isSqlState s SqlError{..} = sqlState == s