@@ -1183,29 +1183,33 @@ async function handleUnary<RequestType, ResponseType>(
1183
1183
metadata : Metadata ,
1184
1184
encoding : string
1185
1185
) : Promise < void > {
1186
- const request = await call . receiveUnaryMessage ( encoding ) ;
1186
+ try {
1187
+ const request = await call . receiveUnaryMessage ( encoding ) ;
1187
1188
1188
- if ( request === undefined || call . cancelled ) {
1189
- return ;
1190
- }
1189
+ if ( request === undefined || call . cancelled ) {
1190
+ return ;
1191
+ }
1191
1192
1192
- const emitter = new ServerUnaryCallImpl < RequestType , ResponseType > (
1193
- call ,
1194
- metadata ,
1195
- request
1196
- ) ;
1193
+ const emitter = new ServerUnaryCallImpl < RequestType , ResponseType > (
1194
+ call ,
1195
+ metadata ,
1196
+ request
1197
+ ) ;
1197
1198
1198
- handler . func (
1199
- emitter ,
1200
- (
1201
- err : ServerErrorResponse | ServerStatusResponse | null ,
1202
- value ?: ResponseType | null ,
1203
- trailer ?: Metadata ,
1204
- flags ?: number
1205
- ) => {
1206
- call . sendUnaryMessage ( err , value , trailer , flags ) ;
1207
- }
1208
- ) ;
1199
+ handler . func (
1200
+ emitter ,
1201
+ (
1202
+ err : ServerErrorResponse | ServerStatusResponse | null ,
1203
+ value ?: ResponseType | null ,
1204
+ trailer ?: Metadata ,
1205
+ flags ?: number
1206
+ ) => {
1207
+ call . sendUnaryMessage ( err , value , trailer , flags ) ;
1208
+ }
1209
+ ) ;
1210
+ } catch ( err ) {
1211
+ call . sendError ( err as ServerErrorResponse )
1212
+ }
1209
1213
}
1210
1214
1211
1215
function handleClientStreaming < RequestType , ResponseType > (
@@ -1245,20 +1249,24 @@ async function handleServerStreaming<RequestType, ResponseType>(
1245
1249
metadata : Metadata ,
1246
1250
encoding : string
1247
1251
) : Promise < void > {
1248
- const request = await call . receiveUnaryMessage ( encoding ) ;
1252
+ try {
1253
+ const request = await call . receiveUnaryMessage ( encoding ) ;
1249
1254
1250
- if ( request === undefined || call . cancelled ) {
1251
- return ;
1252
- }
1255
+ if ( request === undefined || call . cancelled ) {
1256
+ return ;
1257
+ }
1253
1258
1254
- const stream = new ServerWritableStreamImpl < RequestType , ResponseType > (
1255
- call ,
1256
- metadata ,
1257
- handler . serialize ,
1258
- request
1259
- ) ;
1259
+ const stream = new ServerWritableStreamImpl < RequestType , ResponseType > (
1260
+ call ,
1261
+ metadata ,
1262
+ handler . serialize ,
1263
+ request
1264
+ ) ;
1260
1265
1261
- handler . func ( stream ) ;
1266
+ handler . func ( stream ) ;
1267
+ } catch ( err ) {
1268
+ call . sendError ( err as ServerErrorResponse )
1269
+ }
1262
1270
}
1263
1271
1264
1272
function handleBidiStreaming < RequestType , ResponseType > (
0 commit comments