1- import { Metadata , status as Status } from " @grpc/grpc-js" ;
1+ import { Metadata , status as Status } from ' @grpc/grpc-js' ;
22
33export interface GrpcErrorResponse {
44 status : Status ;
@@ -22,7 +22,7 @@ function fourBytesLength(sized: { length: number }): Uint8Array {
2222
2323export function decodeGrpcWebBody ( bodyBuffer : Buffer ) : GrpcResponse {
2424 if ( bodyBuffer . length === 0 ) {
25- throw new Error ( " Body has zero length, cannot decode!" ) ;
25+ throw new Error ( ' Body has zero length, cannot decode!' ) ;
2626 }
2727
2828 const bodyRaw = new Uint8Array ( bodyBuffer ) ;
@@ -53,7 +53,7 @@ export function decodeGrpcWebBody(bodyBuffer: Buffer): GrpcResponse {
5353 const trailersHeader = 0x80 ;
5454
5555 if ( bodyRaw . at ( offset ++ ) !== trailersHeader ) {
56- throw new Error ( " Expected trailers header 0x80" ) ;
56+ throw new Error ( ' Expected trailers header 0x80' ) ;
5757 }
5858
5959 const trailersLength = readInt32Length ( bodyRaw , offset ) ;
@@ -66,16 +66,16 @@ export function decodeGrpcWebBody(bodyBuffer: Buffer): GrpcResponse {
6666
6767 const trailers = new Metadata ( ) ;
6868
69- trailersString . split ( " \r\n" ) . forEach ( ( trailer ) => {
70- const [ key , value ] = trailer . split ( ":" , 2 ) ;
69+ trailersString . split ( ' \r\n' ) . forEach ( ( trailer ) => {
70+ const [ key , value ] = trailer . split ( ':' , 2 ) ;
7171 trailers . set ( key , value ) ;
7272 } ) ;
7373
7474 if ( status !== Status . OK ) {
7575 return {
7676 status,
7777 trailers,
78- detail : trailers . get ( " grpc-message" ) [ 0 ] as string | undefined ,
78+ detail : trailers . get ( ' grpc-message' ) [ 0 ] as string | undefined ,
7979 } ;
8080 }
8181
@@ -99,19 +99,17 @@ export class GrpcUnknownStatus extends Error {
9999
100100export function grpcResponseToBuffer ( response : GrpcResponse ) : Buffer {
101101 // error messages need to have a zero length message field to be considered valid
102- const message = " message" in response ? response . message : new Uint8Array ( ) ;
102+ const message = ' message' in response ? response . message : new Uint8Array ( ) ;
103103
104104 // all success responses have status OK
105- const status = " status" in response ? response . status : Status . OK ;
105+ const status = ' status' in response ? response . status : Status . OK ;
106106 // error statuses may the detail field to denote a custom error message, otherwise use the string version of the status
107107 let grpcMessage : string | undefined ;
108108
109- if ( " detail" in response ) {
109+ if ( ' detail' in response ) {
110110 grpcMessage = response . detail ;
111111 } else {
112- const currentStatus = Object . entries ( Status ) . find (
113- ( [ , code ] ) => code === status
114- ) ;
112+ const currentStatus = Object . entries ( Status ) . find ( ( [ , code ] ) => code === status ) ;
115113
116114 if ( ! currentStatus ) {
117115 throw new GrpcUnknownStatus ( status ) ;
0 commit comments