@@ -25,6 +25,7 @@ import { CreateSSHKeyPairRequest } from '@gitpod/supervisor-api-grpcweb/lib/cont
25
25
import * as ssh2 from 'ssh2' ;
26
26
import { ParsedKey } from 'ssh2-streams' ;
27
27
import { isPortUsed } from '../../common/ports' ;
28
+ import { WrapError } from '../../common/utils' ;
28
29
29
30
const phaseMap : Record < WorkspaceInstanceStatus_Phase , WorkspaceInstancePhase | undefined > = {
30
31
[ WorkspaceInstanceStatus_Phase . CREATING ] : 'pending' ,
@@ -74,6 +75,8 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
74
75
}
75
76
76
77
async getWorkspaceAuthInfo ( request : GetWorkspaceAuthInfoRequest , _context : CallContext ) : Promise < GetWorkspaceAuthInfoResponse > {
78
+ let userId : string | undefined ;
79
+ let instanceId : string | undefined ;
77
80
try {
78
81
if ( new URL ( this . hostService . gitpodHost ) . host !== new URL ( request . gitpodHost ) . host ) {
79
82
this . logService . error ( `gitpod host mismatch, actual: ${ this . hostService . gitpodHost } target: ${ request . gitpodHost } ` ) ;
@@ -83,7 +86,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
83
86
if ( ! accessToken ) {
84
87
throw new ServerError ( Status . INTERNAL , 'no access token found' ) ;
85
88
}
86
- const userId = this . sessionService . getUserId ( ) ;
89
+ userId = this . sessionService . getUserId ( ) ;
87
90
const workspaceId = request . workspaceId ;
88
91
// TODO(lssh): Get auth info according to `request.gitpodHost`
89
92
const gitpodHost = this . hostService . gitpodHost ;
@@ -101,7 +104,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
101
104
}
102
105
const url = new URL ( ideUrl ) ;
103
106
const workspaceHost = url . host . substring ( url . host . indexOf ( '.' ) + 1 ) ;
104
- const instanceId = ( usePublicApi ? ( workspace as Workspace ) . status ?. instance ?. instanceId : ( workspace as WorkspaceInfo ) . latestInstance ?. id ) as string ;
107
+ instanceId = ( usePublicApi ? ( workspace as Workspace ) . status ?. instance ?. instanceId : ( workspace as WorkspaceInfo ) . latestInstance ?. id ) as string ;
105
108
106
109
const sshkey = phase === 'running' ? ( await this . getWorkspaceSSHKey ( ownerToken , workspaceId , workspaceHost ) ) : '' ;
107
110
@@ -116,11 +119,20 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
116
119
phase : phase ?? 'unknown' ,
117
120
} ;
118
121
} catch ( e ) {
119
- this . logService . error ( e , 'failed to get workspace auth info' ) ;
120
- if ( e instanceof ServerError ) {
121
- throw e ;
122
+ let code = Status . INTERNAL ;
123
+ if ( e instanceof WrapError && typeof e . grpcCode === 'number' ) {
124
+ code = e . grpcCode
122
125
}
123
- throw new ServerError ( Status . UNAVAILABLE , e . toString ( ) ) ;
126
+ const wrapErr = new WrapError ( 'failed to get workspace auth info' , e ) ;
127
+ this . logService . error ( wrapErr ) ;
128
+ this . telemetryService . sendTelemetryException ( wrapErr , {
129
+ gitpodHost : request . gitpodHost ,
130
+ workspaceId : request . workspaceId ,
131
+ instanceId,
132
+ userId,
133
+ } ) ;
134
+
135
+ throw new ServerError ( code , wrapErr . toString ( ) ) ;
124
136
}
125
137
}
126
138
0 commit comments