Avoid UnhandledPromiseRejectionWarning on integrity errors

This commit is contained in:
Petri Lehtinen 2018-10-12 07:58:52 +03:00
parent 13eb0ef583
commit 9eb66e7068
2 changed files with 12 additions and 2 deletions

View File

@ -37,10 +37,10 @@ exports.ffiUnsafeQuery = function(client) {
text: sql,
values: values,
rowMode: 'array',
}).catch(function(err) {
onError(err);
}).then(function(result) {
onSuccess(result.rows);
}).catch(function(err) {
onError(err);
});
return function (cancelError, cancelerError, cancelerSuccess) {

View File

@ -10,6 +10,7 @@ import Data.Array (zip)
import Data.Date (Date, canonicalDate)
import Data.DateTime.Instant (Instant, unInstant)
import Data.Decimal as D
import Data.Either (isLeft)
import Data.Enum (toEnum)
import Data.Foldable (all, length)
import Data.JSDate (JSDate, jsdate, toInstant)
@ -169,6 +170,15 @@ main = void $ launchAff do
""") Row0
liftEffect <<< assert $ sauerkrautPrice == [Row1 (D.fromString "3.30")]
test conn "constraint failure" $ do
withTransaction conn $ do
result <- try $ execute conn (Query """
INSERT INTO foods (name)
VALUES ($1)
""") (Row1 "pork")
liftEffect <<< assert $ isLeft result
testCount 0
test conn "handling date value" $ do
let
d1 = date 2010 2 31