Skip to content

Commit

Permalink
feat: add meta-data to stream error (#620)
Browse files Browse the repository at this point in the history
* feat: add meta-data to stream error

* fix last commit

Co-authored-by: Francois HERSENT <[email protected]>
  • Loading branch information
hersentino and hersentino authored Jul 21, 2022
1 parent 9778fa3 commit b68f301
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions integration/grpc-web/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,13 +956,16 @@ export class GrpcWebImpl {
metadata: maybeCombinedMetadata,
debug: this.options.debug,
onMessage: (next) => observer.next(next),
onEnd: (code: grpc.Code, message: string) => {
onEnd: (code: grpc.Code, message: string, trailers: grpc.Metadata) => {
if (code === 0) {
observer.complete();
} else if (upStreamCodes.includes(code)) {
setTimeout(upStream, DEFAULT_TIMEOUT_TIME);
} else {
observer.error(new Error(`Error ${code} ${message}`));
const err = new Error(message) as any;
err.code = code;
err.metadata = trailers;
observer.error(err);
}
},
});
Expand Down
7 changes: 5 additions & 2 deletions src/generate-grpc-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,16 @@ function createInvokeMethod(ctx: Context) {
metadata: maybeCombinedMetadata,
debug: this.options.debug,
onMessage: (next) => observer.next(next),
onEnd: (code: ${grpc}.Code, message: string) => {
onEnd: (code: ${grpc}.Code, message: string, trailers: ${grpc}.Metadata) => {
if (code === 0) {
observer.complete();
} else if (upStreamCodes.includes(code)) {
setTimeout(upStream, DEFAULT_TIMEOUT_TIME);
} else {
observer.error(new Error(\`Error \${code} \${message}\`));
const err = new Error(message) as any;
err.code = code;
err.metadata = trailers;
observer.error(err);
}
},
});
Expand Down

0 comments on commit b68f301

Please sign in to comment.