@libp2p/daemon-client 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/dht.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CID } from 'multiformats/cid'
2
2
  import { multiaddr } from '@multiformats/multiaddr'
3
- import errcode from 'err-code'
3
+ import { CodeError } from '@libp2p/interfaces/errors'
4
4
  import {
5
5
  Request,
6
6
  Response,
@@ -24,11 +24,11 @@ export class DHT {
24
24
  */
25
25
  async put (key: Uint8Array, value: Uint8Array): Promise<void> {
26
26
  if (!(key instanceof Uint8Array)) {
27
- throw errcode(new Error('invalid key received'), 'ERR_INVALID_KEY')
27
+ throw new CodeError('invalid key received', 'ERR_INVALID_KEY')
28
28
  }
29
29
 
30
30
  if (!(value instanceof Uint8Array)) {
31
- throw errcode(new Error('value received is not a Uint8Array'), 'ERR_INVALID_VALUE')
31
+ throw new CodeError('value received is not a Uint8Array', 'ERR_INVALID_VALUE')
32
32
  }
33
33
 
34
34
  const sh = await this.client.send({
@@ -43,7 +43,7 @@ export class DHT {
43
43
  const message = await sh.read()
44
44
 
45
45
  if (message == null) {
46
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
46
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
47
47
  }
48
48
 
49
49
  const response = Response.decode(message)
@@ -51,7 +51,7 @@ export class DHT {
51
51
  await sh.close()
52
52
 
53
53
  if (response.type !== Response.Type.OK) {
54
- throw errcode(new Error(response.error?.msg ?? 'DHT put failed'), 'ERR_DHT_PUT_FAILED')
54
+ throw new CodeError(response.error?.msg ?? 'DHT put failed', 'ERR_DHT_PUT_FAILED')
55
55
  }
56
56
  }
57
57
 
@@ -60,7 +60,7 @@ export class DHT {
60
60
  */
61
61
  async get (key: Uint8Array): Promise<Uint8Array> {
62
62
  if (!(key instanceof Uint8Array)) {
63
- throw errcode(new Error('invalid key received'), 'ERR_INVALID_KEY')
63
+ throw new CodeError('invalid key received', 'ERR_INVALID_KEY')
64
64
  }
65
65
 
66
66
  const sh = await this.client.send({
@@ -74,7 +74,7 @@ export class DHT {
74
74
  const message = await sh.read()
75
75
 
76
76
  if (message == null) {
77
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
77
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
78
78
  }
79
79
 
80
80
  const response = Response.decode(message)
@@ -82,11 +82,11 @@ export class DHT {
82
82
  await sh.close()
83
83
 
84
84
  if (response.type !== Response.Type.OK) {
85
- throw errcode(new Error(response.error?.msg ?? 'DHT get failed'), 'ERR_DHT_GET_FAILED')
85
+ throw new CodeError(response.error?.msg ?? 'DHT get failed', 'ERR_DHT_GET_FAILED')
86
86
  }
87
87
 
88
88
  if (response.dht == null || response.dht.value == null) {
89
- throw errcode(new Error('Invalid DHT get response'), 'ERR_DHT_GET_FAILED')
89
+ throw new CodeError('Invalid DHT get response', 'ERR_DHT_GET_FAILED')
90
90
  }
91
91
 
92
92
  return response.dht.value
@@ -97,7 +97,7 @@ export class DHT {
97
97
  */
98
98
  async findPeer (peerId: PeerId): Promise<PeerInfo> {
99
99
  if (!isPeerId(peerId)) {
100
- throw errcode(new Error('invalid peer id received'), 'ERR_INVALID_PEER_ID')
100
+ throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID')
101
101
  }
102
102
 
103
103
  const sh = await this.client.send({
@@ -111,7 +111,7 @@ export class DHT {
111
111
  const message = await sh.read()
112
112
 
113
113
  if (message == null) {
114
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
114
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
115
115
  }
116
116
 
117
117
  const response = Response.decode(message)
@@ -119,11 +119,11 @@ export class DHT {
119
119
  await sh.close()
120
120
 
121
121
  if (response.type !== Response.Type.OK) {
122
- throw errcode(new Error(response.error?.msg ?? 'DHT find peer failed'), 'ERR_DHT_FIND_PEER_FAILED')
122
+ throw new CodeError(response.error?.msg ?? 'DHT find peer failed', 'ERR_DHT_FIND_PEER_FAILED')
123
123
  }
124
124
 
125
125
  if (response.dht == null || response.dht.peer == null || response.dht.peer.addrs == null) {
126
- throw errcode(new Error('Invalid response'), 'ERR_DHT_FIND_PEER_FAILED')
126
+ throw new CodeError('Invalid response', 'ERR_DHT_FIND_PEER_FAILED')
127
127
  }
128
128
 
129
129
  return {
@@ -138,7 +138,7 @@ export class DHT {
138
138
  */
139
139
  async provide (cid: CID) {
140
140
  if (cid == null || CID.asCID(cid) == null) {
141
- throw errcode(new Error('invalid cid received'), 'ERR_INVALID_CID')
141
+ throw new CodeError('invalid cid received', 'ERR_INVALID_CID')
142
142
  }
143
143
 
144
144
  const sh = await this.client.send({
@@ -152,7 +152,7 @@ export class DHT {
152
152
  const message = await sh.read()
153
153
 
154
154
  if (message == null) {
155
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
155
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
156
156
  }
157
157
 
158
158
  const response = Response.decode(message)
@@ -160,7 +160,7 @@ export class DHT {
160
160
  await sh.close()
161
161
 
162
162
  if (response.type !== Response.Type.OK) {
163
- throw errcode(new Error(response.error?.msg ?? 'DHT provide failed'), 'ERR_DHT_PROVIDE_FAILED')
163
+ throw new CodeError(response.error?.msg ?? 'DHT provide failed', 'ERR_DHT_PROVIDE_FAILED')
164
164
  }
165
165
  }
166
166
 
@@ -169,7 +169,7 @@ export class DHT {
169
169
  */
170
170
  async * findProviders (cid: CID, count: number = 1): AsyncIterable<PeerInfo> {
171
171
  if (cid == null || CID.asCID(cid) == null) {
172
- throw errcode(new Error('invalid cid received'), 'ERR_INVALID_CID')
172
+ throw new CodeError('invalid cid received', 'ERR_INVALID_CID')
173
173
  }
174
174
 
175
175
  const sh = await this.client.send({
@@ -184,7 +184,7 @@ export class DHT {
184
184
  let message = await sh.read()
185
185
 
186
186
  if (message == null) {
187
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
187
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
188
188
  }
189
189
 
190
190
  // stream begin message
@@ -192,14 +192,14 @@ export class DHT {
192
192
 
193
193
  if (response.type !== Response.Type.OK) {
194
194
  await sh.close()
195
- throw errcode(new Error(response.error?.msg ?? 'DHT find providers failed'), 'ERR_DHT_FIND_PROVIDERS_FAILED')
195
+ throw new CodeError(response.error?.msg ?? 'DHT find providers failed', 'ERR_DHT_FIND_PROVIDERS_FAILED')
196
196
  }
197
197
 
198
198
  while (true) {
199
199
  message = await sh.read()
200
200
 
201
201
  if (message == null) {
202
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
202
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
203
203
  }
204
204
 
205
205
  const response = DHTResponse.decode(message)
@@ -220,7 +220,7 @@ export class DHT {
220
220
  } else {
221
221
  // Unexpected message received
222
222
  await sh.close()
223
- throw errcode(new Error('unexpected message received'), 'ERR_UNEXPECTED_MESSAGE_RECEIVED')
223
+ throw new CodeError('unexpected message received', 'ERR_UNEXPECTED_MESSAGE_RECEIVED')
224
224
  }
225
225
  }
226
226
  }
@@ -230,7 +230,7 @@ export class DHT {
230
230
  */
231
231
  async * getClosestPeers (key: Uint8Array): AsyncIterable<PeerInfo> {
232
232
  if (!(key instanceof Uint8Array)) {
233
- throw errcode(new Error('invalid key received'), 'ERR_INVALID_KEY')
233
+ throw new CodeError('invalid key received', 'ERR_INVALID_KEY')
234
234
  }
235
235
 
236
236
  const sh = await this.client.send({
@@ -245,21 +245,21 @@ export class DHT {
245
245
  let message = await sh.read()
246
246
 
247
247
  if (message == null) {
248
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
248
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
249
249
  }
250
250
 
251
251
  const response = Response.decode(message)
252
252
 
253
253
  if (response.type !== Response.Type.OK) {
254
254
  await sh.close()
255
- throw errcode(new Error(response.error?.msg ?? 'DHT find providers failed'), 'ERR_DHT_FIND_PROVIDERS_FAILED')
255
+ throw new CodeError(response.error?.msg ?? 'DHT find providers failed', 'ERR_DHT_FIND_PROVIDERS_FAILED')
256
256
  }
257
257
 
258
258
  while (true) {
259
259
  message = await sh.read()
260
260
 
261
261
  if (message == null) {
262
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
262
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
263
263
  }
264
264
 
265
265
  const response = DHTResponse.decode(message)
@@ -282,7 +282,7 @@ export class DHT {
282
282
  } else {
283
283
  // Unexpected message received
284
284
  await sh.close()
285
- throw errcode(new Error('unexpected message received'), 'ERR_UNEXPECTED_MESSAGE_RECEIVED')
285
+ throw new CodeError('unexpected message received', 'ERR_UNEXPECTED_MESSAGE_RECEIVED')
286
286
  }
287
287
  }
288
288
  }
@@ -292,7 +292,7 @@ export class DHT {
292
292
  */
293
293
  async getPublicKey (peerId: PeerId) {
294
294
  if (!isPeerId(peerId)) {
295
- throw errcode(new Error('invalid peer id received'), 'ERR_INVALID_PEER_ID')
295
+ throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID')
296
296
  }
297
297
 
298
298
  const sh = await this.client.send({
@@ -306,7 +306,7 @@ export class DHT {
306
306
  const message = await sh.read()
307
307
 
308
308
  if (message == null) {
309
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
309
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
310
310
  }
311
311
 
312
312
  const response = Response.decode(message)
@@ -314,11 +314,11 @@ export class DHT {
314
314
  await sh.close()
315
315
 
316
316
  if (response.type !== Response.Type.OK) {
317
- throw errcode(new Error(response.error?.msg ?? 'DHT get public key failed'), 'ERR_DHT_GET_PUBLIC_KEY_FAILED')
317
+ throw new CodeError(response.error?.msg ?? 'DHT get public key failed', 'ERR_DHT_GET_PUBLIC_KEY_FAILED')
318
318
  }
319
319
 
320
320
  if (response.dht == null) {
321
- throw errcode(new Error('Invalid response'), 'ERR_DHT_GET_PUBLIC_KEY_FAILED')
321
+ throw new CodeError('Invalid response', 'ERR_DHT_GET_PUBLIC_KEY_FAILED')
322
322
  }
323
323
 
324
324
  return response.dht.value
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import errcode from 'err-code'
1
+ import { CodeError } from '@libp2p/interfaces/errors'
2
2
  import { tcp } from '@libp2p/tcp'
3
3
  import { PSMessage, Request, Response, StreamInfo } from '@libp2p/daemon-protocol'
4
4
  import { StreamHandler } from '@libp2p/daemon-protocol/stream-handler'
@@ -64,16 +64,16 @@ class Client implements DaemonClient {
64
64
  */
65
65
  async connect (peerId: PeerId, addrs: Multiaddr[]) {
66
66
  if (!isPeerId(peerId)) {
67
- throw errcode(new Error('invalid peer id received'), 'ERR_INVALID_PEER_ID')
67
+ throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID')
68
68
  }
69
69
 
70
70
  if (!Array.isArray(addrs)) {
71
- throw errcode(new Error('addrs received are not in an array'), 'ERR_INVALID_ADDRS_TYPE')
71
+ throw new CodeError('addrs received are not in an array', 'ERR_INVALID_ADDRS_TYPE')
72
72
  }
73
73
 
74
74
  addrs.forEach((addr) => {
75
75
  if (!isMultiaddr(addr)) {
76
- throw errcode(new Error('received an address that is not a multiaddr'), 'ERR_NO_MULTIADDR_RECEIVED')
76
+ throw new CodeError('received an address that is not a multiaddr', 'ERR_NO_MULTIADDR_RECEIVED')
77
77
  }
78
78
  })
79
79
 
@@ -87,13 +87,13 @@ class Client implements DaemonClient {
87
87
 
88
88
  const message = await sh.read()
89
89
  if (message == null) {
90
- throw errcode(new Error('unspecified'), 'ERR_CONNECT_FAILED')
90
+ throw new CodeError('unspecified', 'ERR_CONNECT_FAILED')
91
91
  }
92
92
 
93
93
  const response = Response.decode(message)
94
94
  if (response.type !== Response.Type.OK) {
95
95
  const errResponse = response.error ?? { msg: 'unspecified' }
96
- throw errcode(new Error(errResponse.msg ?? 'unspecified'), 'ERR_CONNECT_FAILED')
96
+ throw new CodeError(errResponse.msg ?? 'unspecified', 'ERR_CONNECT_FAILED')
97
97
  }
98
98
 
99
99
  await sh.close()
@@ -116,17 +116,17 @@ class Client implements DaemonClient {
116
116
  const message = await sh.read()
117
117
 
118
118
  if (message == null) {
119
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
119
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
120
120
  }
121
121
 
122
122
  const response = Response.decode(message)
123
123
 
124
124
  if (response.type !== Response.Type.OK) {
125
- throw errcode(new Error(response.error?.msg ?? 'Identify failed'), 'ERR_IDENTIFY_FAILED')
125
+ throw new CodeError(response.error?.msg ?? 'Identify failed', 'ERR_IDENTIFY_FAILED')
126
126
  }
127
127
 
128
128
  if (response.identify == null || response.identify.addrs == null) {
129
- throw errcode(new Error('Invalid response'), 'ERR_IDENTIFY_FAILED')
129
+ throw new CodeError('Invalid response', 'ERR_IDENTIFY_FAILED')
130
130
  }
131
131
 
132
132
  const peerId = peerIdFromBytes(response.identify?.id)
@@ -148,13 +148,13 @@ class Client implements DaemonClient {
148
148
  const message = await sh.read()
149
149
 
150
150
  if (message == null) {
151
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
151
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
152
152
  }
153
153
 
154
154
  const response = Response.decode(message)
155
155
 
156
156
  if (response.type !== Response.Type.OK) {
157
- throw errcode(new Error(response.error?.msg ?? 'List peers failed'), 'ERR_LIST_PEERS_FAILED')
157
+ throw new CodeError(response.error?.msg ?? 'List peers failed', 'ERR_LIST_PEERS_FAILED')
158
158
  }
159
159
 
160
160
  await sh.close()
@@ -167,11 +167,11 @@ class Client implements DaemonClient {
167
167
  */
168
168
  async openStream (peerId: PeerId, protocol: string): Promise<Duplex<Uint8ArrayList, Uint8Array>> {
169
169
  if (!isPeerId(peerId)) {
170
- throw errcode(new Error('invalid peer id received'), 'ERR_INVALID_PEER_ID')
170
+ throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID')
171
171
  }
172
172
 
173
173
  if (typeof protocol !== 'string') {
174
- throw errcode(new Error('invalid protocol received'), 'ERR_INVALID_PROTOCOL')
174
+ throw new CodeError('invalid protocol received', 'ERR_INVALID_PROTOCOL')
175
175
  }
176
176
 
177
177
  const sh = await this.send({
@@ -185,14 +185,14 @@ class Client implements DaemonClient {
185
185
  const message = await sh.read()
186
186
 
187
187
  if (message == null) {
188
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
188
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
189
189
  }
190
190
 
191
191
  const response = Response.decode(message)
192
192
 
193
193
  if (response.type !== Response.Type.OK) {
194
194
  await sh.close()
195
- throw errcode(new Error(response.error?.msg ?? 'Open stream failed'), 'ERR_OPEN_STREAM_FAILED')
195
+ throw new CodeError(response.error?.msg ?? 'Open stream failed', 'ERR_OPEN_STREAM_FAILED')
196
196
  }
197
197
 
198
198
  return sh.rest()
@@ -203,7 +203,7 @@ class Client implements DaemonClient {
203
203
  */
204
204
  async registerStreamHandler (protocol: string, handler: StreamHandlerFunction): Promise<void> {
205
205
  if (typeof protocol !== 'string') {
206
- throw errcode(new Error('invalid protocol received'), 'ERR_INVALID_PROTOCOL')
206
+ throw new CodeError('invalid protocol received', 'ERR_INVALID_PROTOCOL')
207
207
  }
208
208
 
209
209
  // open a tcp port, pipe any data from it to the handler function
@@ -219,13 +219,13 @@ class Client implements DaemonClient {
219
219
  const message = await sh.read()
220
220
 
221
221
  if (message == null) {
222
- throw errcode(new Error('Could not read open stream response'), 'ERR_OPEN_STREAM_FAILED')
222
+ throw new CodeError('Could not read open stream response', 'ERR_OPEN_STREAM_FAILED')
223
223
  }
224
224
 
225
225
  const response = StreamInfo.decode(message)
226
226
 
227
227
  if (response.proto !== protocol) {
228
- throw errcode(new Error('Incorrect protocol'), 'ERR_OPEN_STREAM_FAILED')
228
+ throw new CodeError('Incorrect protocol', 'ERR_OPEN_STREAM_FAILED')
229
229
  }
230
230
 
231
231
  await handler(sh.rest())
@@ -246,7 +246,7 @@ class Client implements DaemonClient {
246
246
  const address = listener.getAddrs()[0]
247
247
 
248
248
  if (address == null) {
249
- throw errcode(new Error('Could not listen on port'), 'ERR_REGISTER_STREAM_HANDLER_FAILED')
249
+ throw new CodeError('Could not listen on port', 'ERR_REGISTER_STREAM_HANDLER_FAILED')
250
250
  }
251
251
 
252
252
  const sh = await this.send({
@@ -260,7 +260,7 @@ class Client implements DaemonClient {
260
260
  const message = await sh.read()
261
261
 
262
262
  if (message == null) {
263
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
263
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
264
264
  }
265
265
 
266
266
  const response = Response.decode(message)
@@ -268,7 +268,7 @@ class Client implements DaemonClient {
268
268
  await sh.close()
269
269
 
270
270
  if (response.type !== Response.Type.OK) {
271
- throw errcode(new Error(response.error?.msg ?? 'Register stream handler failed'), 'ERR_REGISTER_STREAM_HANDLER_FAILED')
271
+ throw new CodeError(response.error?.msg ?? 'Register stream handler failed', 'ERR_REGISTER_STREAM_HANDLER_FAILED')
272
272
  }
273
273
  }
274
274
  }
package/src/pubsub.ts CHANGED
@@ -1,4 +1,4 @@
1
- import errcode from 'err-code'
1
+ import { CodeError } from '@libp2p/interfaces/errors'
2
2
  import {
3
3
  Request,
4
4
  Response,
@@ -30,7 +30,7 @@ export class Pubsub {
30
30
  const message = await sh.read()
31
31
 
32
32
  if (message == null) {
33
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
33
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
34
34
  }
35
35
 
36
36
  const response = Response.decode(message)
@@ -38,11 +38,11 @@ export class Pubsub {
38
38
  await sh.close()
39
39
 
40
40
  if (response.type !== Response.Type.OK) {
41
- throw errcode(new Error(response.error?.msg ?? 'Pubsub get topics failed'), 'ERR_PUBSUB_GET_TOPICS_FAILED')
41
+ throw new CodeError(response.error?.msg ?? 'Pubsub get topics failed', 'ERR_PUBSUB_GET_TOPICS_FAILED')
42
42
  }
43
43
 
44
44
  if (response.pubsub == null || response.pubsub.topics == null) {
45
- throw errcode(new Error('Invalid response'), 'ERR_PUBSUB_GET_TOPICS_FAILED')
45
+ throw new CodeError('Invalid response', 'ERR_PUBSUB_GET_TOPICS_FAILED')
46
46
  }
47
47
 
48
48
  return response.pubsub.topics
@@ -53,11 +53,11 @@ export class Pubsub {
53
53
  */
54
54
  async publish (topic: string, data: Uint8Array) {
55
55
  if (typeof topic !== 'string') {
56
- throw errcode(new Error('invalid topic received'), 'ERR_INVALID_TOPIC')
56
+ throw new CodeError('invalid topic received', 'ERR_INVALID_TOPIC')
57
57
  }
58
58
 
59
59
  if (!(data instanceof Uint8Array)) {
60
- throw errcode(new Error('data received is not a Uint8Array'), 'ERR_INVALID_DATA')
60
+ throw new CodeError('data received is not a Uint8Array', 'ERR_INVALID_DATA')
61
61
  }
62
62
 
63
63
  const sh = await this.client.send({
@@ -72,7 +72,7 @@ export class Pubsub {
72
72
  const message = await sh.read()
73
73
 
74
74
  if (message == null) {
75
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
75
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
76
76
  }
77
77
 
78
78
  const response = Response.decode(message)
@@ -80,7 +80,7 @@ export class Pubsub {
80
80
  await sh.close()
81
81
 
82
82
  if (response.type !== Response.Type.OK) {
83
- throw errcode(new Error(response.error?.msg ?? 'Pubsub publish failed'), 'ERR_PUBSUB_PUBLISH_FAILED')
83
+ throw new CodeError(response.error?.msg ?? 'Pubsub publish failed', 'ERR_PUBSUB_PUBLISH_FAILED')
84
84
  }
85
85
  }
86
86
 
@@ -89,7 +89,7 @@ export class Pubsub {
89
89
  */
90
90
  async * subscribe (topic: string) {
91
91
  if (typeof topic !== 'string') {
92
- throw errcode(new Error('invalid topic received'), 'ERR_INVALID_TOPIC')
92
+ throw new CodeError('invalid topic received', 'ERR_INVALID_TOPIC')
93
93
  }
94
94
 
95
95
  const sh = await this.client.send({
@@ -103,13 +103,13 @@ export class Pubsub {
103
103
  let message = await sh.read()
104
104
 
105
105
  if (message == null) {
106
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
106
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
107
107
  }
108
108
 
109
109
  const response = Response.decode(message)
110
110
 
111
111
  if (response.type !== Response.Type.OK) {
112
- throw errcode(new Error(response.error?.msg ?? 'Pubsub publish failed'), 'ERR_PUBSUB_PUBLISH_FAILED')
112
+ throw new CodeError(response.error?.msg ?? 'Pubsub publish failed', 'ERR_PUBSUB_PUBLISH_FAILED')
113
113
  }
114
114
 
115
115
  // stream messages
@@ -117,7 +117,7 @@ export class Pubsub {
117
117
  message = await sh.read()
118
118
 
119
119
  if (message == null) {
120
- throw errcode(new Error('Empty response from remote'), 'ERR_EMPTY_RESPONSE')
120
+ throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE')
121
121
  }
122
122
 
123
123
  yield PSMessage.decode(message)