@@ -18,14 +18,19 @@ import { ExperimentalSettings } from '../../experiments';
18
18
import { Configuration } from '../../configuration' ;
19
19
import { timeout } from '../../common/async' ;
20
20
import { BrowserHeaders } from 'browser-headers' ;
21
- import { ControlServiceClient } from '@gitpod/supervisor-api-grpcweb/lib/control_pb_service' ;
21
+ import { ControlServiceClient , ServiceError } from '@gitpod/supervisor-api-grpcweb/lib/control_pb_service' ;
22
22
import { NodeHttpTransport } from '@improbable-eng/grpc-web-node-http-transport' ;
23
23
import { CreateSSHKeyPairRequest } from '@gitpod/supervisor-api-grpcweb/lib/control_pb' ;
24
24
import * as ssh2 from 'ssh2' ;
25
25
import { ParsedKey } from 'ssh2-streams' ;
26
26
import { isPortUsed } from '../../common/ports' ;
27
27
import { WrapError } from '../../common/utils' ;
28
- import { ConnectError } from '@bufbuild/connect' ;
28
+ import { ConnectError , Code } from '@bufbuild/connect' ;
29
+
30
+ function isServiceError ( obj : any ) : obj is ServiceError {
31
+ // eslint-disable-next-line eqeqeq
32
+ return obj != null && typeof obj === 'object' && typeof obj . metadata != null && typeof obj . code === 'number' && typeof obj . message === 'string' ;
33
+ }
29
34
30
35
const phaseMap : Record < WorkspaceInstanceStatus_Phase , WorkspaceInstancePhase | undefined > = {
31
36
[ WorkspaceInstanceStatus_Phase . CREATING ] : 'pending' ,
@@ -60,7 +65,9 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
60
65
const privateKey = await new Promise < string > ( ( resolve , reject ) => {
61
66
client . createSSHKeyPair ( new CreateSSHKeyPairRequest ( ) , metadata , ( err , resp ) => {
62
67
if ( err ) {
63
- return reject ( err ) ;
68
+ // codes of grpc-web are align with grpc and connect
69
+ // see https://github.com/improbable-eng/grpc-web/blob/1d9bbb09a0990bdaff0e37499570dbc7d6e58ce8/client/grpc-web/src/Code.ts#L1
70
+ return reject ( new WrapError ( 'Failed to call supervisor API' , err , 'SupervisorAPI:' + Code [ err . code ] ) ) ;
64
71
}
65
72
resolve ( resp ! . toObject ( ) . privateKey ) ;
66
73
} ) ;
@@ -124,8 +131,8 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
124
131
} ;
125
132
} catch ( e ) {
126
133
let code = Status . INTERNAL ;
127
- if ( e instanceof WrapError && e . cause instanceof ConnectError ) {
128
- code = e . cause . code as unknown as Status ;
134
+ if ( e instanceof WrapError && ( e . cause instanceof ConnectError || isServiceError ( e . cause ) ) ) {
135
+ code = e . cause . code ;
129
136
}
130
137
const wrapErr = new WrapError ( 'failed to get workspace auth info' , e ) ;
131
138
this . logService . error ( wrapErr ) ;
@@ -134,6 +141,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
134
141
workspaceId : request . workspaceId ,
135
142
instanceId,
136
143
userId,
144
+ wrapCode : wrapErr . code ,
137
145
} ) ;
138
146
139
147
throw new ServerError ( code , wrapErr . toString ( ) ) ;
0 commit comments