You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Important**: Don't pass clients from `pg`'s `Pool` to `PostgresPubSub`. As [node-postgres creator states in this StackOverflow answer](https://stackoverflow.com/questions/8484404/what-is-the-proper-way-to-use-the-node-js-postgresql-module), the client needs to be around and not shared so pg can properly handle `NOTIFY` messages (which this library uses under the hood)
55
55
56
+
## Error handling
57
+
58
+
`PostgresPubSub` instances emit a special event called `"error"`. This event's payload is an instance of Javascript's `Error`. You can get the error's text using `error.message`.
59
+
60
+
```js
61
+
constps=newPostgresPubSub({ client });
62
+
63
+
ps.subscribe("error", err=> {
64
+
console.log(err.message); // -> "payload string too long"
65
+
}).then(() =>ps.publish("a", "a".repeat(9000)));
66
+
```
67
+
68
+
For example you can log all error messages (including stack traces and friends) using something like this:
69
+
70
+
```js
71
+
ps.subscribe("error", console.error);
72
+
```
73
+
56
74
## Development
57
75
58
76
This project has an integration test suite that uses [`jest`](https://facebook.github.io/jest/) to make sure everything works correctly.
59
77
60
78
We use Docker to spin up a PostgreSQL instance before running the tests. To run them, type the following commands:
0 commit comments