@@ -111,50 +111,50 @@ class LightPush extends BaseProtocol implements ILightPush {
111
111
}
112
112
113
113
const promises = peers . map ( async ( peer ) => {
114
- let error : SendError | undefined ;
115
-
116
114
let stream : Stream | undefined ;
117
115
try {
118
116
stream = await this . getStream ( peer ) ;
119
117
} catch ( err ) {
120
118
log ( `Failed to get a stream for remote peer${ peer . id . toString ( ) } ` , err ) ;
121
- error = SendError . REMOTE_PEER_FAULT ;
122
- return { recipients, error } ;
119
+ return { recipients, error : SendError . REMOTE_PEER_FAULT } ;
123
120
}
124
121
122
+ let res : Uint8ArrayList [ ] | undefined ;
125
123
try {
126
- const res = await pipe (
124
+ res = await pipe (
127
125
[ query . encode ( ) ] ,
128
126
lp . encode ,
129
127
stream ,
130
128
lp . decode ,
131
129
async ( source ) => await all ( source )
132
130
) ;
133
- try {
134
- const bytes = new Uint8ArrayList ( ) ;
135
- res . forEach ( ( chunk ) => {
136
- bytes . append ( chunk ) ;
137
- } ) ;
138
-
139
- const response = PushRpc . decode ( bytes ) . response ;
140
-
141
- if ( response ?. isSuccess ) {
142
- recipients . some ( ( recipient ) => recipient . equals ( peer . id ) ) ||
143
- recipients . push ( peer . id ) ;
144
- } else {
145
- log ( "Remote peer fault: No response in PushRPC" ) ;
146
- error = SendError . REMOTE_PEER_FAULT ;
147
- }
148
- } catch ( err ) {
149
- log ( "Failed to decode push reply" , err ) ;
150
- error = SendError . DECODE_FAILED ;
151
- }
152
131
} catch ( err ) {
153
132
log ( "Failed to send waku light push request" , err ) ;
154
- error = SendError . GENERIC_FAIL ;
133
+ return { recipients, error : SendError . GENERIC_FAIL } ;
134
+ }
135
+
136
+ const bytes = new Uint8ArrayList ( ) ;
137
+ res . forEach ( ( chunk ) => {
138
+ bytes . append ( chunk ) ;
139
+ } ) ;
140
+
141
+ let response : PushResponse | undefined ;
142
+ try {
143
+ response = PushRpc . decode ( bytes ) . response ;
144
+ } catch ( err ) {
145
+ log ( "Failed to decode push reply" , err ) ;
146
+ return { recipients, error : SendError . DECODE_FAILED } ;
147
+ }
148
+
149
+ if ( response ?. isSuccess ) {
150
+ recipients . some ( ( recipient ) => recipient . equals ( peer . id ) ) ||
151
+ recipients . push ( peer . id ) ;
152
+ } else {
153
+ log ( "Remote peer fault: No response in PushRPC" ) ;
154
+ return { recipients, error : SendError . REMOTE_PEER_FAULT } ;
155
155
}
156
156
157
- return { recipients, error } ;
157
+ return { recipients } ;
158
158
} ) ;
159
159
160
160
const results = await Promise . allSettled ( promises ) ;
0 commit comments